@@ -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)
30+import Prelude hiding (all, any, take, unzip, span)
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.
@@ -162,6 +162,24 @@ classifyWith f = S.fold (FL.classifyWith f FL.sum)
162unzip :: Monad m => SerialT m Int -> m (Int, Int)
162unzip :: Monad m => SerialT m Int -> m (Int, Int)
163unzip = IP.fold $ FL.map (\a -> (a, a)) (FL.unzip FL.sum FL.length)
163unzip = IP.fold $ FL.map (\a -> (a, a)) (FL.unzip FL.sum FL.length)
165+-------------------------------------------------------------------------------
167+-------------------------------------------------------------------------------
170+span :: Monad m => Int -> SerialT m Int -> m ((), ())
171+span bound = S.fold (FL.span (<= (bound `div` 2)) FL.drain FL.drain)
173+{-# INLINE spanBy #-}
174+spanBy :: Monad m => Int -> SerialT m Int -> m ((), ())
176+ S.fold (FL.spanBy (\_ i -> i <= (bound `div` 2)) FL.drain FL.drain)
178+{-# INLINE spanByRolling #-}
179+spanByRolling :: Monad m => Int -> SerialT m Int -> m ((), ())
180+spanByRolling bound =
181+ S.fold (FL.spanByRolling (\_ i -> i <= (bound `div` 2)) FL.drain FL.drain)
165-------------------------------------------------------------------------------
183-------------------------------------------------------------------------------
166-- Benchmarks
184-- Benchmarks
167-------------------------------------------------------------------------------
185-------------------------------------------------------------------------------
@@ -274,6 +292,9 @@ o_1_space_serial_composition value =
274 $ demuxDefaultWith fn mp
292 $ demuxDefaultWith fn mp
275 , benchIOSink value "demuxWith [sum, length]" $ demuxWith fn mp
293 , benchIOSink value "demuxWith [sum, length]" $ demuxWith fn mp
276 , benchIOSink value "classifyWith sum" $ classifyWith (fst . fn)
294 , benchIOSink value "classifyWith sum" $ classifyWith (fst . fn)
295+ , benchIOSink value "span" $ span value
296+ , benchIOSink value "spanBy" $ spanBy value
297+ , benchIOSink value "spanByRolling" $ spanByRolling value