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------------------------------------------------------------------------------
25data BenchType = Linear | LinearAsync | LinearRate | Nested | Base | FileIO
31 , benchType :: BenchType
34defaultOptions = Options False False Linear
38 put (args, opts { genGraphs = val })
42 put (args, opts { groupDiff = val })
46 put (args, opts { benchType = val })
48-- Like the shell "shift" to shift the command line arguments
49shift :: StateT ([String], Options) (MaybeT IO) (Maybe String)
53 ([], _) -> return Nothing
54 (x : xs, opts) -> put (xs, opts) >> return (Just x)
56parseBench :: StateT ([String], Options) (MaybeT IO) ()
60 Just "linear" -> setBenchType Linear
61 Just "linear-async" -> setBenchType LinearAsync
62 Just "linear-rate" -> setBenchType LinearRate
63 Just "nested" -> setBenchType Nested
64 Just "base" -> setBenchType Base
65 Just "fileio" -> setBenchType FileIO
67 liftIO $ putStrLn $ "unrecognized benchmark type " <> str
70 liftIO $ putStrLn "please provide a benchmark type "
73-- totally imperative style option parsing
74parseOptions :: IO (Maybe Options)
77 runMaybeT $ flip evalStateT (args, defaultOptions) $ do
85 "--graphs" -> setGenGraphs True
86 "--group-diff" -> setGroupDiff True
87 "--benchmark" -> parseBench
89 liftIO $ putStrLn $ "Unrecognized option " <> str
95 Just opt -> parseOpt opt >> parseLoop
98ignoringErr a = catch a (\(ErrorCall err :: ErrorCall) ->
99 putStrLn $ "Failed with error:\n" <> err <> "\nSkipping.")
101------------------------------------------------------------------------------
102-- Linear composition charts
103------------------------------------------------------------------------------
105makeLinearGraphs :: Config -> String -> IO ()
106makeLinearGraphs cfg@Config{..} inputFile = do
107 ignoringErr $ graph inputFile "generation" $ cfg
108 { title = (++) <$> title <*> Just " generation"
109 , classifyBenchmark =
110 fmap ("Streamly",) . stripPrefix "serially/generation/"
113 ignoringErr $ graph inputFile "elimination" $ cfg
114 { title = (++) <$> title <*> Just " Elimination"
115 , classifyBenchmark =
116 fmap ("Streamly",) . stripPrefix "serially/elimination/"
119 ignoringErr $ graph inputFile "transformation-zip" $ cfg
120 { title = (++) <$> title <*> Just " Transformation & Zip"
121 , classifyBenchmark = \b ->
122 if "serially/transformation/" `isPrefixOf` b
123 || "serially/zipping" `isPrefixOf` b
124 then Just ("Streamly", last $ splitOn "/" b)
128 ignoringErr $ graph inputFile "filtering" $ cfg
129 { title = (++) <$> title <*> Just " Filtering"
130 , classifyBenchmark =
131 fmap ("Streamly",) . stripPrefix "serially/filtering/"
134 ignoringErr $ graph inputFile "transformationX4" $ cfg
135 { title = (++) <$> title <*> Just " Transformation x 4"
136 , classifyBenchmark =
137 fmap ("Streamly",) . stripPrefix "serially/transformationX4/"
140 ignoringErr $ graph inputFile "filteringX4"
142 { title = (++) <$> title <*> Just " Filtering x 4"
143 , classifyBenchmark =
144 fmap ("Streamly",) . stripPrefix "serially/filteringX4/"
147 ignoringErr $ graph inputFile "mixedX4"
149 { title = (++) <$> title <*> Just " Mixed x 4"
150 , classifyBenchmark =
151 fmap ("Streamly",) . stripPrefix "serially/mixedX4/"
154 ignoringErr $ graph inputFile "iterated"
156 { title = Just "iterate 10,000 times over 10 elems"
157 , classifyBenchmark =
158 fmap ("Streamly",) . stripPrefix "serially/iterated/"
161------------------------------------------------------------------------------
162-- Nested composition charts
163------------------------------------------------------------------------------
165makeNestedGraphs :: Config -> String -> IO ()
166makeNestedGraphs cfg inputFile =
167 ignoringErr $ graph inputFile "nested-all" $ cfg
168 { presentation = Groups Absolute
169 , classifyBenchmark = classifyNested
170 , selectGroups = \gs ->
171 groupBy ((==) `on` snd) gs
172 & fmap (\xs -> mapMaybe (\x -> (x,) <$> lookup x xs) order)
178 order = ["serially", "asyncly", "wAsyncly", "aheadly", "parallely"]
181 | "serially/" `isPrefixOf` b =
182 ("serially",) <$> stripPrefix "serially/" b
183 | "asyncly/" `isPrefixOf` b =
184 ("asyncly",) <$> stripPrefix "asyncly/" b
185 | "wAsyncly/" `isPrefixOf` b =
186 ("wAsyncly",) <$> stripPrefix "wAsyncly/" b
187 | "aheadly/" `isPrefixOf` b =
188 ("aheadly",) <$> stripPrefix "aheadly/" b
189 | "parallely/" `isPrefixOf` b =
190 ("parallely",) <$> stripPrefix "parallely/" b
191 | otherwise = Nothing
193------------------------------------------------------------------------------
194-- Charts for parallel streams
195------------------------------------------------------------------------------
197makeLinearAsyncGraphs :: Config -> String -> IO ()
198makeLinearAsyncGraphs cfg inputFile =
199 ignoringErr $ graph inputFile "linear-async" cfg
200 { presentation = Groups Absolute
201 , classifyBenchmark = classifyAsync
202 , selectGroups = \gs ->
203 groupBy ((==) `on` snd) gs
204 & fmap (\xs -> mapMaybe (\x -> (x,) <$> lookup x xs) order)
210 order = ["asyncly", "wAsyncly", "aheadly", "parallely"]
213 | "asyncly/" `isPrefixOf` b =
214 ("asyncly",) <$> stripPrefix "asyncly/" b
215 | "wAsyncly/" `isPrefixOf` b =
216 ("wAsyncly",) <$> stripPrefix "wAsyncly/" b
217 | "aheadly/" `isPrefixOf` b =
218 ("aheadly",) <$> stripPrefix "aheadly/" b
219 | "parallely/" `isPrefixOf` b =
220 ("parallely",) <$> stripPrefix "parallely/" b
221 | otherwise = Nothing
223makeLinearRateGraphs :: Config -> String -> IO ()
224makeLinearRateGraphs cfg inputFile = do
225 putStrLn "Not implemented"
228------------------------------------------------------------------------------
230------------------------------------------------------------------------------
232makeFileIOGraphs :: Config -> String -> IO ()
233makeFileIOGraphs cfg@Config{..} inputFile =
234 ignoringErr $ graph inputFile "fileIO" cfg
236------------------------------------------------------------------------------
237-- Reports/Charts for base streams
238------------------------------------------------------------------------------
240showStreamDVsK Options{..} cfg inp out =
241 let cfg' = cfg { classifyBenchmark = classifyBase }
243 then ignoringErr $ graph inp "streamD-vs-streamK"
244 cfg' { outputDir = Just out
245 , presentation = Groups Absolute
247 else ignoringErr $ report inp Nothing cfg'
252 | "streamD/" `isPrefixOf` b = ("streamD",) <$> stripPrefix "streamD/" b
253 | "streamK/" `isPrefixOf` b = ("streamK",) <$> stripPrefix "streamK/" b
254 | otherwise = Nothing
256showStreamD Options{..} cfg inp out =
257 let cfg' = cfg { classifyBenchmark = classifyStreamD }
259 then ignoringErr $ graph inp "streamD"
260 cfg' {outputDir = Just out}
261 else ignoringErr $ report inp Nothing cfg'
266 | "streamD/" `isPrefixOf` b = ("streamD",) <$> stripPrefix "streamD/" b
267 | otherwise = Nothing
269showStreamK Options{..} cfg inp out =
270 let cfg' = cfg { classifyBenchmark = classifyStreamK }
272 then ignoringErr $ graph inp "streamK"
273 cfg' {outputDir = Just out}
274 else ignoringErr $ report inp Nothing cfg'
279 | "streamK/" `isPrefixOf` b = ("streamK",) <$> stripPrefix "streamK/" b
280 | otherwise = Nothing
282------------------------------------------------------------------------------
284------------------------------------------------------------------------------
286selectBench :: (SortColumn -> Either String [(String, Double)]) -> [String]
291 (const $ either error (sortOn snd) $ f $ ColumnIndex 0)
295benchShow Options{..} cfg func inp out =
297 then func cfg {outputDir = Just out} inp
298 else ignoringErr $ report inp Nothing cfg
302 let cfg = defaultConfig
303 { presentation = Groups PercentDiff
304 , selectBenchmarks = selectBench
310 putStrLn "cannot parse options"
312 Just opts@Options{..} ->
314 Linear -> benchShow opts cfg
315 { title = Just "100,000 elems" }
317 "charts/linear/results.csv"
319 LinearAsync -> benchShow opts cfg
320 { title = Just "Async 10,000 elems" }
321 makeLinearAsyncGraphs
322 "charts/linear-async/results.csv"
323 "charts/linear-async"
324 LinearRate -> benchShow opts cfg makeLinearRateGraphs
325 "charts/linear-rate/results.csv"
327 Nested -> benchShow opts cfg
328 { title = Just "Nested loops 100 x 100 elems" }
330 "charts/nested/results.csv"
332 FileIO -> benchShow opts cfg
333 { title = Just "File IO" }
335 "charts/fileio/results.csv"
338 let cfg' = cfg { title = Just "100,000 elems" }
340 then showStreamDVsK opts cfg'
341 "charts/base/results.csv"
344 showStreamD opts cfg'
345 "charts/base/results.csv"
347 showStreamK opts cfg'
348 "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