@@ -1,3 +1,4 @@
2-- Module : Main
3-- Module : Main
3-- Copyright : (c) 2018 Harendra Kumar
4-- Copyright : (c) 2018 Harendra Kumar
@@ -31,6 +32,10 @@ benchSrcIO
31benchSrcIO t name f
32benchSrcIO t name f
32 = bench name $ nfIO $ randomRIO (1,1) >>= Ops.toNull t . f
33 = bench name $ nfIO $ randomRIO (1,1) >>= Ops.toNull t . f
35+{-# INLINE benchMonadicSrcIO #-}
36+benchMonadicSrcIO :: String -> (Int -> IO ()) -> Benchmark
37+benchMonadicSrcIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
35_benchId :: NFData b => String -> (Ops.Stream m Int -> Identity b) -> Benchmark
40_benchId :: NFData b => String -> (Ops.Stream m Int -> Identity b) -> Benchmark
36_benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
41_benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
@@ -38,7 +43,13 @@ _benchId name f = bench name $ nf (runIdentity . f) (Ops.source 10)
39main :: IO ()
44main :: IO ()
41− defaultMain
46+ defaultMainWith (defaultConfig
49+#ifdef LONG_BENCHMARKS
50+ , includeFirstIter = True
42 [ bgroup "asyncly"
53 [ bgroup "asyncly"
43 [ benchSrcIO asyncly "unfoldr" Ops.sourceUnfoldr
54 [ benchSrcIO asyncly "unfoldr" Ops.sourceUnfoldr
44 , benchSrcIO asyncly "unfoldrM" Ops.sourceUnfoldrM
55 , benchSrcIO asyncly "unfoldrM" Ops.sourceUnfoldrM
@@ -52,8 +63,12 @@ main =
52 , benchIO "mapM" $ Ops.mapM asyncly 1
63 , benchIO "mapM" $ Ops.mapM asyncly 1
53 , benchSrcIO asyncly "unfoldrM maxThreads 1"
64 , benchSrcIO asyncly "unfoldrM maxThreads 1"
54 (maxThreads 1 . Ops.sourceUnfoldrM)
65 (maxThreads 1 . Ops.sourceUnfoldrM)
55− , benchSrcIO asyncly "unfoldrM maxBuffer 1 (1000 ops)"
66+ , benchSrcIO asyncly "unfoldrM maxBuffer 1 (x/10 ops)"
56− (maxBuffer 1 . Ops.sourceUnfoldrMN 1000)
67+ (maxBuffer 1 . Ops.sourceUnfoldrMN (Ops.value `div` 10))
68+ , benchMonadicSrcIO "concatMapWith (2,x/2)"
69+ (Ops.concatStreamsWith async 2 (Ops.value `div` 2))
70+ , benchMonadicSrcIO "concatMapWith (x/2,2)"
71+ (Ops.concatStreamsWith async (Ops.value `div` 2) 2)
58 , bgroup "wAsyncly"
73 , bgroup "wAsyncly"
59 [ benchSrcIO wAsyncly "unfoldr" Ops.sourceUnfoldr
74 [ benchSrcIO wAsyncly "unfoldr" Ops.sourceUnfoldr
@@ -66,6 +81,10 @@ main =
66 , benchIO "map" $ Ops.map' wAsyncly 1
81 , benchIO "map" $ Ops.map' wAsyncly 1
67 , benchIO "fmap" $ Ops.fmap' wAsyncly 1
82 , benchIO "fmap" $ Ops.fmap' wAsyncly 1
68 , benchIO "mapM" $ Ops.mapM wAsyncly 1
83 , benchIO "mapM" $ Ops.mapM wAsyncly 1
84+ , benchMonadicSrcIO "concatMapWith (2,x/2)"
85+ (Ops.concatStreamsWith wAsync 2 (Ops.value `div` 2))
86+ , benchMonadicSrcIO "concatMapWith (x/2,2)"
87+ (Ops.concatStreamsWith wAsync (Ops.value `div` 2) 2)
70 -- unfoldr and fromFoldable are always serial and thereofore the same for
89 -- unfoldr and fromFoldable are always serial and thereofore the same for
71 -- all stream types.
90 -- all stream types.
@@ -81,9 +100,13 @@ main =
81 , benchIO "mapM" $ Ops.mapM aheadly 1
100 , benchIO "mapM" $ Ops.mapM aheadly 1
82 , benchSrcIO aheadly "unfoldrM maxThreads 1"
101 , benchSrcIO aheadly "unfoldrM maxThreads 1"
83 (maxThreads 1 . Ops.sourceUnfoldrM)
102 (maxThreads 1 . Ops.sourceUnfoldrM)
84− , benchSrcIO aheadly "unfoldrM maxBuffer 1 (1000 ops)"
103+ , benchSrcIO aheadly "unfoldrM maxBuffer 1 (x/10 ops)"
85− (maxBuffer 1 . Ops.sourceUnfoldrMN 1000)
104+ (maxBuffer 1 . Ops.sourceUnfoldrMN (Ops.value `div` 10))
86 -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
105 -- , benchSrcIO aheadly "fromFoldable" Ops.sourceFromFoldable
106+ , benchMonadicSrcIO "concatMapWith (2,x/2)"
107+ (Ops.concatStreamsWith ahead 2 (Ops.value `div` 2))
108+ , benchMonadicSrcIO "concatMapWith (x/2,2)"
109+ (Ops.concatStreamsWith ahead (Ops.value `div` 2) 2)
88 -- XXX need to use smaller streams to finish in reasonable time
111 -- XXX need to use smaller streams to finish in reasonable time
89 , bgroup "parallely"
112 , bgroup "parallely"
@@ -104,5 +127,9 @@ main =
104 -- Parallel stages in a pipeline
127 -- Parallel stages in a pipeline
105 , benchIO "parAppMap" Ops.parAppMap
128 , benchIO "parAppMap" Ops.parAppMap
106 , benchIO "parAppSum" Ops.parAppSum
129 , benchIO "parAppSum" Ops.parAppSum
130+ , benchMonadicSrcIO "concatMapWith (2,x/2)"
131+ (Ops.concatStreamsWith parallel 2 (Ops.value `div` 2))
132+ , benchMonadicSrcIO "concatMapWith (x/10,10)"
133+ (Ops.concatStreamsWith parallel (Ops.value `div` 10) 10)