on master help sign in
Add a foldBreak benchmark for StreamD
37e226eHarendra Kumar
benchmark/Streamly/Benchmark/Data/Stream/StreamD.hs+8
@@ -29,6 +29,7 @@ import Prelude hiding (tail, mapM_, foldl, last, map, mapM, concatMap, zip)
29import qualified Prelude as P
29import qualified Prelude as P
30import qualified Streamly.Internal.Data.Stream.StreamD as S
30import qualified Streamly.Internal.Data.Stream.StreamD as S
31import qualified Streamly.Internal.Data.Unfold as UF
31import qualified Streamly.Internal.Data.Unfold as UF
32+import qualified Streamly.Internal.Data.Fold as FL
32
33
33import Streamly.Benchmark.Common
34import Streamly.Benchmark.Common
34
35
@@ -125,6 +126,12 @@ uncons s = do
125 Nothing -> return ()
126 Nothing -> return ()
126 Just (_, t) -> uncons t
127 Just (_, t) -> uncons t
127
128
129+{-# INLINE foldBreak #-}
130+foldBreak :: Monad m => Stream m Int -> m ()
131+foldBreak s = do
132+ (r, s1) <- S.foldBreak (FL.take 1 FL.length) s
133+ when (r /= 0) $ foldBreak s1
134+
128{-# INLINE tail #-}
135{-# INLINE tail #-}
129tail :: Monad m => Stream m a -> m ()
136tail :: Monad m => Stream m a -> m ()
130tail s = S.tail s >>= P.mapM_ tail
137tail s = S.tail s >>= P.mapM_ tail
@@ -439,6 +446,7 @@ o_1_space =
439 [ benchFold "toNull" toNull sourceUnfoldrM
446 [ benchFold "toNull" toNull sourceUnfoldrM
440 , benchFold "mapM_" mapM_ sourceUnfoldrM
447 , benchFold "mapM_" mapM_ sourceUnfoldrM
441 , benchFold "uncons" uncons sourceUnfoldrM
448 , benchFold "uncons" uncons sourceUnfoldrM
449+ , benchFold "foldBreak" foldBreak sourceUnfoldrM
442 , benchFold "foldl'" foldl sourceUnfoldrM
450 , benchFold "foldl'" foldl sourceUnfoldrM
443 , benchFold "last" last sourceUnfoldrM
451 , benchFold "last" last sourceUnfoldrM
444 ]
452 ]