on 9034b2d help sign in
streamly/benchmark/NestedConcurrent.hs
84 lines 3.5 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 Control.Monad (when)
10import Data.Functor.Identity (Identity, runIdentity)
11import System.Random (randomRIO)
13import Common (parseCLIOpts)
15import Streamly
16import Gauge
18import qualified NestedOps as Ops
20benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
21benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
23_benchId :: (NFData b) => String -> (Int -> Identity b) -> Benchmark
24_benchId name f = bench name $ nf (\g -> runIdentity (g 1)) f
26defaultStreamSize :: Int
27defaultStreamSize = 100000
29main :: IO ()
30main = do
31 -- XXX Fix indentation
32 (linearCount, cfg, benches) <- parseCLIOpts defaultStreamSize
33 let finiteCount = min linearCount defaultStreamSize
34 when (finiteCount /= linearCount) $
35 putStrLn $ "Limiting stream size to "
36 ++ show defaultStreamSize
37 ++ " for finite stream operations only"
39 finiteCount `seq` linearCount `seq` runMode (mode cfg) cfg benches
40 [
41 bgroup "aheadly"
42 [ benchIO "toNullAp" $ Ops.toNullAp linearCount aheadly
43 , benchIO "toNull" $ Ops.toNull linearCount aheadly
44 , benchIO "toNull3" $ Ops.toNull3 linearCount aheadly
45 -- , benchIO "toList" $ Ops.toList linearCount aheadly
46 -- XXX consumes too much stack space
47 , benchIO "toListSome" $ Ops.toListSome linearCount aheadly
48 , benchIO "filterAllOut" $ Ops.filterAllOut linearCount aheadly
49 , benchIO "filterAllIn" $ Ops.filterAllIn linearCount aheadly
50 , benchIO "filterSome" $ Ops.filterSome linearCount aheadly
51 , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount aheadly
52 ]
54 , bgroup "asyncly"
55 [ benchIO "toNullAp" $ Ops.toNullAp linearCount asyncly
56 , benchIO "toNull" $ Ops.toNull linearCount asyncly
57 , benchIO "toNull3" $ Ops.toNull3 linearCount asyncly
58 -- , benchIO "toList" $ Ops.toList linearCount asyncly
59 , benchIO "toListSome" $ Ops.toListSome linearCount asyncly
60 , benchIO "filterAllOut" $ Ops.filterAllOut linearCount asyncly
61 , benchIO "filterAllIn" $ Ops.filterAllIn linearCount asyncly
62 , benchIO "filterSome" $ Ops.filterSome linearCount asyncly
63 , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount asyncly
64 ]
66 , bgroup "zipAsyncly"
67 [ benchIO "toNullAp" $ Ops.toNullAp linearCount zipAsyncly
68 ]
70 -- Operations that are not scalable to infinite streams
71 , bgroup "finite"
72 [ bgroup "wAsyncly"
73 [ benchIO "toNullAp" $ Ops.toNullAp finiteCount wAsyncly
74 , benchIO "toNull" $ Ops.toNull finiteCount wAsyncly
75 , benchIO "toNull3" $ Ops.toNull3 finiteCount wAsyncly
76 -- , benchIO "toList" $ Ops.toList finiteCount wAsyncly
77 , benchIO "toListSome" $ Ops.toListSome finiteCount wAsyncly
78 , benchIO "filterAllOut" $ Ops.filterAllOut finiteCount wAsyncly
79 -- , benchIO "filterAllIn" $ Ops.filterAllIn finiteCount wAsyncly
80 , benchIO "filterSome" $ Ops.filterSome finiteCount wAsyncly
81 , benchIO "breakAfterSome" $ Ops.breakAfterSome finiteCount wAsyncly
82 ]
83 ]
84 ]