@@ -27,7 +27,7 @@ import qualified Streamly.Prelude as S
28import Gauge
28import Gauge
29import Streamly.Benchmark.Common
29import Streamly.Benchmark.Common
30−import Prelude hiding (all, any, take, unzip, sequence_)
30+import Prelude hiding (all, any, take, unzip, sequence_, filter)
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.
@@ -78,6 +78,25 @@ sequence_ value =
78 {-# INLINE f #-}
78 {-# INLINE f #-}
79 f m k = FL.concatMap (const k) m
79 f m k = FL.concatMap (const k) m
81+-------------------------------------------------------------------------------
83+-------------------------------------------------------------------------------
86+filter :: Monad m => Int -> SerialT m Int -> m ()
87+filter _ = IP.fold (FL.filter even FL.drain)
89+{-# INLINE foldFilter #-}
90+foldFilter :: Monad m => Int -> SerialT m Int -> m ()
91+foldFilter _ = IP.fold (FL.foldFilter (FL.satisfy even) FL.drain)
93+{-# INLINE foldFilter2 #-}
94+foldFilter2 :: Monad m => Int -> SerialT m Int -> m ()
97+ $ FL.foldFilter (FL.satisfy even)
98+ $ FL.foldFilter (FL.satisfy odd) FL.drain
81-------------------------------------------------------------------------------
100-------------------------------------------------------------------------------
82-- Splitting by serial application
101-- Splitting by serial application
83-------------------------------------------------------------------------------
102-------------------------------------------------------------------------------
@@ -323,7 +342,10 @@ o_1_space_serial_composition :: Int -> [Benchmark]
323o_1_space_serial_composition value =
342o_1_space_serial_composition value =
325 "composition"
344 "composition"
345+ [ benchIOSink value "filter even" $ filter value
346+ , benchIOSink value "foldFilter even" $ foldFilter value
347+ , benchIOSink value "foldFilter even, odd" $ foldFilter2 value
326− [ benchIOSink value "serialWith (all, any)" $ splitAllAny value
348+ , benchIOSink value "serialWith (all, any)" $ splitAllAny value
327 , benchIOSink value "serial_ (all, any)" $ serial_ value
349 , benchIOSink value "serial_ (all, any)" $ serial_ value
328 , benchIOSink value "tee (all, any)" $ teeAllAny value
350 , benchIOSink value "tee (all, any)" $ teeAllAny value
329 , benchIOSink value "many drain (take 1)" many
351 , benchIOSink value "many drain (take 1)" many