on master help sign in
Add benchmark for Data.Fold.concatMap.
c1c77d0Pranay Sashank
benchmark/Streamly/Benchmark/Data/Fold.hs+16−1
@@ -27,7 +27,7 @@ import qualified Streamly.Prelude as S
27
27
28import Gauge
28import Gauge
29import Streamly.Benchmark.Common
29import Streamly.Benchmark.Common
30−import Prelude hiding (all, any, take, unzip)
30+import Prelude hiding (all, any, take, unzip, sequence_)
31
31
32-- We need a monadic bind here to make sure that the function f does not get
32-- We need a monadic bind here to make sure that the function f does not get
33-- completely optimized out by the compiler in some cases.
33-- completely optimized out by the compiler in some cases.
@@ -68,6 +68,15 @@ all value = IP.fold (FL.all (<= value))
68takeLE :: Monad m => Int -> SerialT m a -> m ()
68takeLE :: Monad m => Int -> SerialT m a -> m ()
69takeLE value = IP.fold (FL.takeLE value FL.drain)
69takeLE value = IP.fold (FL.takeLE value FL.drain)
70
70
71+{-# INLINE sequence_ #-}
72+sequence_ :: Monad m => Int -> Fold m a ()
73+sequence_ value = foldr f (pure ()) (Prelude.replicate value (FL.takeLE 1 FL.drain))
74+
75+ where
76+
77+ {-# INLINE f #-}
78+ f m k = FL.concatMap (const k) m
79+
71-------------------------------------------------------------------------------
80-------------------------------------------------------------------------------
72-- Splitting by serial application
81-- Splitting by serial application
73-------------------------------------------------------------------------------
82-------------------------------------------------------------------------------
@@ -284,6 +293,11 @@ o_1_space_serial_composition value =
284
293
285 mp = Map.fromList [(0, FL.sum), (1, FL.length)]
294 mp = Map.fromList [(0, FL.sum), (1, FL.length)]
286
295
296+o_n_space_serial :: Int -> [Benchmark]
297+o_n_space_serial value =
298+ [ benchIOSink value "sequence_/100" $ S.fold (sequence_ (value `div` 100))
299+ ]
300+
287o_n_heap_serial :: Int -> [Benchmark]
301o_n_heap_serial :: Int -> [Benchmark]
288o_n_heap_serial value =
302o_n_heap_serial value =
289 [ bgroup "elimination"
303 [ bgroup "elimination"
@@ -312,5 +326,6 @@ main = do
312 , o_1_space_serial_transformation value
326 , o_1_space_serial_transformation value
313 , o_1_space_serial_composition value
327 , o_1_space_serial_composition value
314 ]
328 ]
329+ , bgroup (o_n_space_prefix moduleName) (o_n_space_serial value)
315 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_serial value)
330 , bgroup (o_n_heap_prefix moduleName) (o_n_heap_serial value)
316 ]
331 ]