@@ -18,6 +18,7 @@ import qualified Streamly.Prelude as S
19import Gauge
19import Gauge
20import Streamly.Benchmark.Common hiding (benchPureSrc)
20import Streamly.Benchmark.Common hiding (benchPureSrc)
21+import qualified Streamly.Benchmark.Prelude as P
22#ifdef MEMORY_ARRAY
23#ifdef MEMORY_ARRAY
23import qualified GHC.Exts as GHC
24import qualified GHC.Exts as GHC
@@ -70,26 +71,6 @@ benchIO' name src f = bench name $ nfIO $
70benchIOSink :: NFData b => Int -> String -> (Ops.Stream Int -> IO b) -> Benchmark
71benchIOSink :: NFData b => Int -> String -> (Ops.Stream Int -> IO b) -> Benchmark
71benchIOSink value name f = benchIO' name (Ops.sourceIntFromTo value) f
72benchIOSink value name f = benchIO' name (Ops.sourceIntFromTo value) f
73−{-# INLINE sourceUnfoldrM #-}
74−sourceUnfoldrM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
75−sourceUnfoldrM value n = S.unfoldrM step n
80− else return (Just (cnt, cnt + 1))
83−source :: (S.MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
84−source = sourceUnfoldrM
86− -- | Takes a fold method, and uses it with a default source.
87−{-# INLINE benchIOSinkF #-}
89− :: (S.IsStream t, NFData b)
90− => Int -> String -> (t IO Int -> IO b) -> Benchmark
91−benchIOSinkF value name f = bench name $ nfIO $ randomRIO (1,1) >>= f . source value
93o_1_space_generation :: Int -> [Benchmark]
74o_1_space_generation :: Int -> [Benchmark]
94o_1_space_generation value =
75o_1_space_generation value =
@@ -139,8 +120,8 @@ o_1_space_elimination value =
139 , benchIOSink value "foldl'" Ops.pureFoldl'
120 , benchIOSink value "foldl'" Ops.pureFoldl'
140 , benchIOSink value "read" Ops.unfoldReadDrain
121 , benchIOSink value "read" Ops.unfoldReadDrain
141 , benchIOSink value "toStreamRev" Ops.toStreamRevDrain
122 , benchIOSink value "toStreamRev" Ops.toStreamRevDrain
142− , benchIOSinkF value "lastN.1" (S.fold (IA.lastN 1))
123+ , benchFold "lastN.1" (S.fold (IA.lastN 1)) (P.sourceUnfoldrM value)
143− , benchIOSinkF value "lastN.10" (S.fold (IA.lastN 10))
124+ , benchFold "lastN.10" (S.fold (IA.lastN 10)) (P.sourceUnfoldrM value)
144#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
125#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
145#ifdef DEVBUILD
126#ifdef DEVBUILD
146 , benchPureSink value "foldable/foldl'" Ops.foldableFoldl'
127 , benchPureSink value "foldable/foldl'" Ops.foldableFoldl'
@@ -155,8 +136,10 @@ o_n_heap_serial value =
155 [ bgroup "elimination"
136 [ bgroup "elimination"
157 -- Converting the stream to an array
138 -- Converting the stream to an array
158− benchIOSinkF value "lastN.Max" (S.fold (IA.lastN (value + 1)))
139+ benchFold "lastN.Max" (S.fold (IA.lastN (value + 1)))
140+ (P.sourceUnfoldrM value)
159− , benchIOSinkF value "writeN" (S.fold (A.writeN value))
141+ , benchFold "writeN" (S.fold (A.writeN value))
142+ (P.sourceUnfoldrM value)
@@ -212,6 +195,7 @@ main = do
212 , o_1_space_elimination size
195 , o_1_space_elimination size
213 , o_1_space_transformation size
196 , o_1_space_transformation size
214 , o_1_space_transformationX4 size
197 , o_1_space_transformationX4 size
215− , o_n_heap_serial size
199+ , bgroup (o_n_space_prefix moduleName) $
200+ o_n_heap_serial size