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
10import Data.Function (on, (&))
13import Data.Maybe (mapMaybe)
14import Data.Ord (comparing)
15import System.Environment (getArgs)
16import Control.Monad.IO.Class (liftIO)
17import Control.Monad (mzero)
21------------------------------------------------------------------------------
22-- Command line parsing
23------------------------------------------------------------------------------
39 , benchType :: BenchType
42defaultOptions = Options False False Linear
46 put (args, opts { genGraphs = val })
50 put (args, opts { groupDiff = val })
54 put (args, opts { benchType = val })
56-- Like the shell "shift" to shift the command line arguments
57shift :: StateT ([String], Options) (MaybeT IO) (Maybe String)
61 ([], _) -> return Nothing
62 (x : xs, opts) -> put (xs, opts) >> return (Just x)
64parseBench :: StateT ([String], Options) (MaybeT IO) ()
68 Just "linear" -> setBenchType Linear
69 Just "linear-async" -> setBenchType LinearAsync
70 Just "linear-rate" -> setBenchType LinearRate
71 Just "nested" -> setBenchType Nested
72 Just "base" -> setBenchType Base
73 Just "fileio" -> setBenchType FileIO
74 Just "array" -> setBenchType Array
75 Just "concurrent" -> setBenchType Concurrent
77 liftIO $ putStrLn $ "unrecognized benchmark type " <> str
80 liftIO $ putStrLn "please provide a benchmark type "
83-- totally imperative style option parsing
84parseOptions :: IO (Maybe Options)
87 runMaybeT $ flip evalStateT (args, defaultOptions) $ do
95 "--graphs" -> setGenGraphs True
96 "--group-diff" -> setGroupDiff True
97 "--benchmark" -> parseBench
99 liftIO $ putStrLn $ "Unrecognized option " <> str
105 Just opt -> parseOpt opt >> parseLoop
108ignoringErr a = catch a (\(ErrorCall err :: ErrorCall) ->
109 putStrLn $ "Failed with error:\n" <> err <> "\nSkipping.")
111------------------------------------------------------------------------------
112-- Linear composition charts
113------------------------------------------------------------------------------
115makeLinearGraphs :: Config -> String -> IO ()
116makeLinearGraphs cfg@Config{..} inputFile = do
117 ignoringErr $ graph inputFile "generation" $ cfg
118 { title = (++) <$> title <*> Just " generation"
119 , classifyBenchmark =
120 fmap ("Streamly",) . stripPrefix "serially/generation/"
123 ignoringErr $ graph inputFile "elimination" $ cfg
124 { title = (++) <$> title <*> Just " Elimination"
125 , classifyBenchmark =
126 fmap ("Streamly",) . stripPrefix "serially/elimination/"
129 ignoringErr $ graph inputFile "transformation-zip" $ cfg
130 { title = (++) <$> title <*> Just " Transformation & Zip"
131 , classifyBenchmark = \b ->
132 if "serially/transformation/" `isPrefixOf` b
133 || "serially/zipping" `isPrefixOf` b
134 then Just ("Streamly", last $ splitOn "/" b)
138 ignoringErr $ graph inputFile "filtering" $ cfg
139 { title = (++) <$> title <*> Just " Filtering"
140 , classifyBenchmark =
141 fmap ("Streamly",) . stripPrefix "serially/filtering/"
144 ignoringErr $ graph inputFile "transformationX4" $ cfg
145 { title = (++) <$> title <*> Just " Transformation x 4"
146 , classifyBenchmark =
147 fmap ("Streamly",) . stripPrefix "serially/transformationX4/"
150 ignoringErr $ graph inputFile "filteringX4"
152 { title = (++) <$> title <*> Just " Filtering x 4"
153 , classifyBenchmark =
154 fmap ("Streamly",) . stripPrefix "serially/filteringX4/"
157 ignoringErr $ graph inputFile "mixedX4"
159 { title = (++) <$> title <*> Just " Mixed x 4"
160 , classifyBenchmark =
161 fmap ("Streamly",) . stripPrefix "serially/mixedX4/"
164 ignoringErr $ graph inputFile "iterated"
166 { title = Just "iterate 10,000 times over 10 elems"
167 , classifyBenchmark =
168 fmap ("Streamly",) . stripPrefix "serially/iterated/"
171------------------------------------------------------------------------------
172-- Nested composition charts
173------------------------------------------------------------------------------
175makeNestedGraphs :: Config -> String -> IO ()
176makeNestedGraphs cfg inputFile =
177 ignoringErr $ graph inputFile "nested-all" $ cfg
178 { presentation = Groups Absolute
179 , classifyBenchmark = classifyNested
180 , selectGroups = \gs ->
181 groupBy ((==) `on` snd) gs
182 & fmap (\xs -> mapMaybe (\x -> (x,) <$> lookup x xs) order)
188 order = ["serially", "asyncly", "wAsyncly", "aheadly", "parallely"]
191 | "serially/" `isPrefixOf` b =
192 ("serially",) <$> stripPrefix "serially/" b
193 | "asyncly/" `isPrefixOf` b =
194 ("asyncly",) <$> stripPrefix "asyncly/" b
195 | "wAsyncly/" `isPrefixOf` b =
196 ("wAsyncly",) <$> stripPrefix "wAsyncly/" b
197 | "aheadly/" `isPrefixOf` b =
198 ("aheadly",) <$> stripPrefix "aheadly/" b
199 | "parallely/" `isPrefixOf` b =
200 ("parallely",) <$> stripPrefix "parallely/" b
201 | otherwise = Nothing
203------------------------------------------------------------------------------
204-- Charts for parallel streams
205------------------------------------------------------------------------------
207makeLinearAsyncGraphs :: Config -> String -> IO ()
208makeLinearAsyncGraphs cfg inputFile =
209 ignoringErr $ graph inputFile "linear-async" cfg
210 { presentation = Groups Absolute
211 , classifyBenchmark = classifyAsync
212 , selectGroups = \gs ->
213 groupBy ((==) `on` snd) gs
214 & fmap (\xs -> mapMaybe (\x -> (x,) <$> lookup x xs) order)
220 order = ["asyncly", "wAsyncly", "aheadly", "parallely"]
223 | "asyncly/" `isPrefixOf` b =
224 ("asyncly",) <$> stripPrefix "asyncly/" b
225 | "wAsyncly/" `isPrefixOf` b =
226 ("wAsyncly",) <$> stripPrefix "wAsyncly/" b
227 | "aheadly/" `isPrefixOf` b =
228 ("aheadly",) <$> stripPrefix "aheadly/" b
229 | "parallely/" `isPrefixOf` b =
230 ("parallely",) <$> stripPrefix "parallely/" b
231 | otherwise = Nothing
233makeLinearRateGraphs :: Config -> String -> IO ()
234makeLinearRateGraphs cfg inputFile = do
235 putStrLn "Not implemented"
238------------------------------------------------------------------------------
240------------------------------------------------------------------------------
242makeFileIOGraphs :: Config -> String -> IO ()
243makeFileIOGraphs cfg@Config{..} inputFile =
244 ignoringErr $ graph inputFile "fileIO" cfg
246makeArrayGraphs :: Config -> String -> IO ()
247makeArrayGraphs cfg@Config{..} inputFile =
248 ignoringErr $ graph inputFile "array" cfg
250makeConcurrentGraphs :: Config -> String -> IO ()
251makeConcurrentGraphs cfg@Config{..} inputFile =
252 ignoringErr $ graph inputFile "concurrent" cfg
254------------------------------------------------------------------------------
255-- Reports/Charts for base streams
256------------------------------------------------------------------------------
258showStreamDVsK Options{..} cfg inp out =
259 let cfg' = cfg { classifyBenchmark = classifyBase }
261 then ignoringErr $ graph inp "streamD-vs-streamK"
262 cfg' { outputDir = Just out
263 , presentation = Groups Absolute
265 else ignoringErr $ report inp Nothing cfg'
270 | "streamD/" `isPrefixOf` b = ("streamD",) <$> stripPrefix "streamD/" b
271 | "streamK/" `isPrefixOf` b = ("streamK",) <$> stripPrefix "streamK/" b
272 | otherwise = Nothing
274showStreamD Options{..} cfg inp out =
275 let cfg' = cfg { classifyBenchmark = classifyStreamD }
277 then ignoringErr $ graph inp "streamD"
278 cfg' {outputDir = Just out}
279 else ignoringErr $ report inp Nothing cfg'
284 | "streamD/" `isPrefixOf` b = ("streamD",) <$> stripPrefix "streamD/" b
285 | otherwise = Nothing
287showStreamK Options{..} cfg inp out =
288 let cfg' = cfg { classifyBenchmark = classifyStreamK }
290 then ignoringErr $ graph inp "streamK"
291 cfg' {outputDir = Just out}
292 else ignoringErr $ report inp Nothing cfg'
297 | "streamK/" `isPrefixOf` b = ("streamK",) <$> stripPrefix "streamK/" b
298 | otherwise = Nothing
300------------------------------------------------------------------------------
302------------------------------------------------------------------------------
305 :: (SortColumn -> Maybe GroupStyle -> Either String [(String, Double)])
311 (const $ either error (sortOn snd) $ f (ColumnIndex 0) (Just PercentDiff))
313 $ f (ColumnIndex 1) (Just PercentDiff)
315benchShow Options{..} cfg func inp out =
317 then func cfg {outputDir = Just out} inp
318 else ignoringErr $ report inp Nothing cfg
322 let cfg = defaultConfig
323 { presentation = Groups PercentDiff
324 , selectBenchmarks = selectBench
330 putStrLn "cannot parse options"
332 Just opts@Options{..} ->
334 Linear -> benchShow opts cfg
335 { title = Just "100,000 elems" }
337 "charts/linear/results.csv"
339 LinearAsync -> benchShow opts cfg
340 { title = Just "Async 10,000 elems" }
341 makeLinearAsyncGraphs
342 "charts/linear-async/results.csv"
343 "charts/linear-async"
344 LinearRate -> benchShow opts cfg makeLinearRateGraphs
345 "charts/linear-rate/results.csv"
347 Nested -> benchShow opts cfg
348 { title = Just "Nested loops 100 x 100 elems" }
350 "charts/nested/results.csv"
352 FileIO -> benchShow opts cfg
353 { title = Just "File IO" }
355 "charts/fileio/results.csv"
357 Array -> benchShow opts cfg
358 { title = Just "Array" }
360 "charts/array/results.csv"
362 Concurrent -> benchShow opts cfg
363 { title = Just "Concurrent Ops" }
365 "charts/concurrent/results.csv"
368 let cfg' = cfg { title = Just "100,000 elems" }
370 then showStreamDVsK opts cfg'
371 "charts/base/results.csv"
374 showStreamD opts cfg'
375 "charts/base/results.csv"
377 showStreamK opts cfg'
378 "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