on f684e26 help sign in
streamly/benchmark/NestedConcurrent.hs
90 lines 4.0 kB history raw
1-- |
2-- Module : Main
3-- Copyright : (c) 2018 Harendra Kumar
4--
5-- License : BSD3
6-- Maintainer : streamly@composewell.com
8import Control.DeepSeq (NFData)
9import Data.Functor.Identity (Identity, runIdentity)
10import System.Random (randomRIO)
11import qualified NestedOps as Ops
12import Streamly
13import Gauge
14import System.Environment (getArgs)
15import Text.Read (readMaybe)
17benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
18benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
20_benchId :: (NFData b) => String -> (Int -> Identity b) -> Benchmark
21_benchId name f = bench name $ nf (\g -> runIdentity (g 1)) f
23main :: IO ()
24main = do
25 -- TBD Study scaling with 10, 100, 1000 loop iterations
26 -- Basement.Terminal.initialize required?
27 args <- getArgs
28 let (linearCount, args') = parseValue args
29 (cfg, extra) = parseWith defaultConfig args'
30 runMode (mode cfg) cfg extra
31 [
32 bgroup "aheadly"
33 [ benchIO "toNullAp" $ Ops.toNullAp linearCount aheadly
34 , benchIO "toNull" $ Ops.toNull linearCount aheadly
35 , benchIO "toNull3" $ Ops.toNull3 linearCount aheadly
36 , benchIO "toList" $ Ops.toList linearCount aheadly
37 -- , benchIO "toListSome" $ Ops.toListSome aheadly
38 , benchIO "filterAllOut" $ Ops.filterAllOut linearCount aheadly
39 , benchIO "filterAllIn" $ Ops.filterAllIn linearCount aheadly
40 , benchIO "filterSome" $ Ops.filterSome linearCount aheadly
41 , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount aheadly
42 ]
44 , bgroup "asyncly"
45 [ benchIO "toNullAp" $ Ops.toNullAp linearCount asyncly
46 , benchIO "toNull" $ Ops.toNull linearCount asyncly
47 , benchIO "toNull3" $ Ops.toNull3 linearCount asyncly
48 , benchIO "toList" $ Ops.toList linearCount asyncly
49 -- , benchIO "toListSome" $ Ops.toListSome asyncly
50 , benchIO "filterAllOut" $ Ops.filterAllOut linearCount asyncly
51 , benchIO "filterAllIn" $ Ops.filterAllIn linearCount asyncly
52 , benchIO "filterSome" $ Ops.filterSome linearCount asyncly
53 , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount asyncly
54 ]
56 , bgroup "wAsyncly"
57 [ benchIO "toNullAp" $ Ops.toNullAp linearCount wAsyncly
58 , benchIO "toNull" $ Ops.toNull linearCount wAsyncly
59 , benchIO "toNull3" $ Ops.toNull3 linearCount wAsyncly
60 , benchIO "toList" $ Ops.toList linearCount wAsyncly
61 -- , benchIO "toListSome" $ Ops.toListSome wAsyncly
62 , benchIO "filterAllOut" $ Ops.filterAllOut linearCount wAsyncly
63 , benchIO "filterAllIn" $ Ops.filterAllIn linearCount wAsyncly
64 , benchIO "filterSome" $ Ops.filterSome linearCount wAsyncly
65 , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount wAsyncly
66 ]
68 , bgroup "parallely"
69 [ benchIO "toNullAp" $ Ops.toNullAp linearCount parallely
70 , benchIO "toNull" $ Ops.toNull linearCount parallely
71 , benchIO "toNull3" $ Ops.toNull3 linearCount parallely
72 , benchIO "toList" $ Ops.toList linearCount parallely
73 --, benchIO "toListSome" $ Ops.toListSome parallely
74 , benchIO "filterAllOut" $ Ops.filterAllOut linearCount parallely
75 , benchIO "filterAllIn" $ Ops.filterAllIn linearCount parallely
76 , benchIO "filterSome" $ Ops.filterSome linearCount parallely
77 , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount parallely
78 ]
80 , bgroup "zipAsyncly"
81 [ benchIO "toNullAp" $ Ops.toNullAp linearCount zipAsyncly
82 ]
83 ]
84 where
85 defaultValue = 100000
86 parseValue [] = (defaultValue, [])
87 parseValue a@(x:xs) =
88 case (readMaybe x :: Maybe Int) of
89 Just value -> (value, xs)
90 Nothing -> (defaultValue, a)