1{-# LANGUAGE TupleSections #-}
2{-# LANGUAGE RecordWildCards #-}
3{-# LANGUAGE ScopedTypeVariables #-}
7import Control.Exception (handle, catch, SomeException, ErrorCall(..))
8import Control.Monad.Trans.State
9import Control.Monad.Trans.Maybe
12import Data.Ord (comparing)
13import System.Environment (getArgs)
14import Control.Monad.IO.Class (liftIO)
15import Control.Monad (mzero)
19------------------------------------------------------------------------------
20-- Command line parsing
21------------------------------------------------------------------------------
23data BenchType = Linear | LinearAsync | LinearRate | Nested | Base
27 , benchType :: BenchType
30defaultOptions = Options False Linear
34 put (args, opts { genGraphs = val })
38 put (args, opts { benchType = val })
40-- Like the shell "shift" to shift the command line arguments
41shift :: StateT ([String], Options) (MaybeT IO) (Maybe String)
45 ([], _) -> return Nothing
46 (x : xs, opts) -> put (xs, opts) >> return (Just x)
48parseBench :: StateT ([String], Options) (MaybeT IO) ()
52 Just "linear" -> setBenchType Linear
53 Just "linear-async" -> setBenchType LinearAsync
54 Just "linear-rate" -> setBenchType LinearRate
55 Just "nested" -> setBenchType Nested
56 Just "base" -> setBenchType Base
58 liftIO $ putStrLn $ "unrecognized benchmark type " <> str
61 liftIO $ putStrLn "please provide a benchmark type "
64-- totally imperative style option parsing
65parseOptions :: IO (Maybe Options)
68 runMaybeT $ flip evalStateT (args, defaultOptions) $ do
71 Just "--graphs" -> setGenGraphs True
72 Just "--benchmark" -> parseBench
74 liftIO $ putStrLn $ "Unrecognized option " <> str
79ignoringErr a = catch a (\(ErrorCall err :: ErrorCall) ->
80 putStrLn $ "Failed with error:\n" <> err <> "\nSkipping.")
82------------------------------------------------------------------------------
83-- Linear composition charts
84------------------------------------------------------------------------------
86makeLinearGraphs :: Config -> String -> IO ()
87makeLinearGraphs cfg inputFile = do
88 ignoringErr $ graph inputFile "generation" $ cfg
89 { title = Just "Generation"
91 fmap ("Streamly",) . stripPrefix "serially/generation/"
94 ignoringErr $ graph inputFile "elimination" $ cfg
95 { title = Just "Elimination"
97 fmap ("Streamly",) . stripPrefix "serially/elimination/"
100 ignoringErr $ graph inputFile "transformation-zip" $ cfg
101 { title = Just "Transformation & Zip"
102 , classifyBenchmark = \b ->
103 if "serially/transformation/" `isPrefixOf` b
104 || "serially/zip" `isPrefixOf` b
105 then Just ("Streamly", last $ splitOn "/" b)
109 ignoringErr $ graph inputFile "filtering" $ cfg
110 { title = Just "Filtering"
111 , classifyBenchmark =
112 fmap ("Streamly",) . stripPrefix "serially/filtering/"
115 ignoringErr $ graph inputFile "composed-transformation" $ cfg
116 { title = Just "Composed Transformation"
117 , classifyBenchmark =
118 fmap ("Streamly",) . stripPrefix "serially/transformationN/"
121 ignoringErr $ graph inputFile "composed-filtering"
123 { title = Just "Composed Filtering"
124 , classifyBenchmark =
125 fmap ("Streamly",) . stripPrefix "serially/filteringN/"
128 ignoringErr $ graph inputFile "composed-mixed"
130 { title = Just "Composed Mixed"
131 , classifyBenchmark =
132 fmap ("Streamly",) . stripPrefix "serially/composed/"
135 ignoringErr $ graph inputFile "iterated"
137 { title = Just "Iterated Ops"
138 , classifyBenchmark =
139 fmap ("Streamly",) . stripPrefix "serially/iterated/"
142------------------------------------------------------------------------------
143-- Nested composition charts
144------------------------------------------------------------------------------
146makeNestedGraphs :: Config -> String -> IO ()
147makeNestedGraphs cfg inputFile =
148 ignoringErr $ graph inputFile "nested-serial" $ cfg
149 { title = Just "Nested serial"
150 , classifyBenchmark = \b ->
151 let ls = splitOn "/" b
153 "serially" -> Just (head ls, last ls)
157------------------------------------------------------------------------------
158-- Charts for parallel streams
159------------------------------------------------------------------------------
161makeLinearAsyncGraphs :: Config -> String -> IO ()
162makeLinearAsyncGraphs cfg inputFile = do
163 putStrLn "Not implemented"
166makeLinearRateGraphs :: Config -> String -> IO ()
167makeLinearRateGraphs cfg inputFile = do
168 putStrLn "Not implemented"
171------------------------------------------------------------------------------
172-- Charts for base streams
173------------------------------------------------------------------------------
175makeBaseGraphs :: Config -> String -> IO ()
176makeBaseGraphs cfg inputFile = do
177 putStrLn "Not implemented"
180------------------------------------------------------------------------------
182------------------------------------------------------------------------------
184selectBench :: (SortColumn -> Either String [(String, Double)]) -> [String]
189 (const $ either error (sortOn snd) $ f $ ColumnIndex 0)
193benchShow Options{..} cfg func inp out =
195 then func cfg {outputDir = Just out} inp
196 else ignoringErr $ report inp Nothing cfg
198showStreamDVsK Options{..} cfg func inp out =
199 let cfg' = cfg { classifyBenchmark = classify }
201 then ignoringErr $ graph inp "streamD-vs-streamK"
202 cfg' {outputDir = Just out}
203 else ignoringErr $ report inp Nothing cfg'
208 | "streamD/" `isPrefixOf` b = ("streamD",) <$> stripPrefix "streamD/" b
209 | "streamK/" `isPrefixOf` b = ("streamK",) <$> stripPrefix "streamK/" b
210 | otherwise = Nothing
214 let cfg = defaultConfig
215 { presentation = Groups PercentDiff
216 , selectBenchmarks = selectBench
222 putStrLn "cannot parse options"
224 Just opts@Options{..} ->
226 Linear -> benchShow opts cfg makeLinearGraphs
227 "charts/linear/results.csv"
229 LinearAsync -> benchShow opts cfg makeLinearAsyncGraphs
230 "charts/linear-async/results.csv"
231 "charts/linear-async"
232 LinearRate -> benchShow opts cfg makeLinearRateGraphs
233 "charts/linear-rate/results.csv"
235 Nested -> benchShow opts cfg makeNestedGraphs
236 "charts/nested/results.csv"
238 Base -> showStreamDVsK opts cfg makeBaseGraphs
239 "charts/base/results.csv"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list