on master help sign in
Add benchmarks for S.concatFoldableWith and S.concatForFoldableWith
06b230fadithyaov
benchmark/Streamly/Benchmark/Prelude/Ahead.hs+4
@@ -57,6 +57,10 @@ o_1_space_concatFoldable value =
57 (sourceFoldMapWithStream value)
57 (sourceFoldMapWithStream value)
58 , benchIOSrc aheadly "foldMapWithM (<>) (List)"
58 , benchIOSrc aheadly "foldMapWithM (<>) (List)"
59 (sourceFoldMapWithM value)
59 (sourceFoldMapWithM value)
60+ , benchIOSrc serially "S.concatFoldableWith (<>) (List)"
61+ (concatFoldableWith value)
62+ , benchIOSrc serially "S.concatForFoldableWith (<>) (List)"
63+ (concatForFoldableWith value)
60 , benchIOSrc aheadly "foldMapM (List)" (sourceFoldMapM value)
64 , benchIOSrc aheadly "foldMapM (List)" (sourceFoldMapM value)
61 ]
65 ]
62 ]
66 ]
benchmark/Streamly/Benchmark/Prelude/Async.hs+4
@@ -114,6 +114,10 @@ o_1_space_concatFoldable value =
114 (sourceFoldMapWithStream value)
114 (sourceFoldMapWithStream value)
115 , benchIOSrc asyncly "foldMapWithM (<>) (List)"
115 , benchIOSrc asyncly "foldMapWithM (<>) (List)"
116 (sourceFoldMapWithM value)
116 (sourceFoldMapWithM value)
117+ , benchIOSrc serially "S.concatFoldableWith (<>) (List)"
118+ (concatFoldableWith value)
119+ , benchIOSrc serially "S.concatForFoldableWith (<>) (List)"
120+ (concatForFoldableWith value)
117 , benchIOSrc asyncly "foldMapM (List)" (sourceFoldMapM value)
121 , benchIOSrc asyncly "foldMapM (List)" (sourceFoldMapM value)
118 ]
122 ]
119 ]
123 ]
benchmark/Streamly/Benchmark/Prelude/Parallel.hs+4
@@ -130,6 +130,10 @@ o_n_heap_concatFoldable value =
130 (sourceFoldMapWithStream value)
130 (sourceFoldMapWithStream value)
131 , benchIOSrc parallely "foldMapWithM (<>) (List)"
131 , benchIOSrc parallely "foldMapWithM (<>) (List)"
132 (sourceFoldMapWithM value)
132 (sourceFoldMapWithM value)
133+ , benchIOSrc serially "S.concatFoldableWith (<>) (List)"
134+ (concatFoldableWith value)
135+ , benchIOSrc serially "S.concatForFoldableWith (<>) (List)"
136+ (concatForFoldableWith value)
133 , benchIOSrc parallely "foldMapM (List)" (sourceFoldMapM value)
137 , benchIOSrc parallely "foldMapM (List)" (sourceFoldMapM value)
134 ]
138 ]
135 ]
139 ]
benchmark/Streamly/Benchmark/Prelude/Serial.hs+4
@@ -1746,6 +1746,10 @@ o_1_space_concatFoldable value =
1746 (sourceFoldMapWithStream value)
1746 (sourceFoldMapWithStream value)
1747 , benchIOSrc serially "foldMapWithM (<>) (List)"
1747 , benchIOSrc serially "foldMapWithM (<>) (List)"
1748 (sourceFoldMapWithM value)
1748 (sourceFoldMapWithM value)
1749+ , benchIOSrc serially "S.concatFoldableWith (<>) (List)"
1750+ (concatFoldableWith value)
1751+ , benchIOSrc serially "S.concatForFoldableWith (<>) (List)"
1752+ (concatForFoldableWith value)
1749 , benchIOSrc serially "foldMapM (List)" (sourceFoldMapM value)
1753 , benchIOSrc serially "foldMapM (List)" (sourceFoldMapM value)
1750 ]
1754 ]
1751 ]
1755 ]
benchmark/Streamly/Benchmark/Prelude/WAsync.hs+4
@@ -62,6 +62,10 @@ o_1_space_concatFoldable value =
62 (sourceFoldMapWithStream value)
62 (sourceFoldMapWithStream value)
63 , benchIOSrc wAsyncly "foldMapWithM (<>) (List)"
63 , benchIOSrc wAsyncly "foldMapWithM (<>) (List)"
64 (sourceFoldMapWithM value)
64 (sourceFoldMapWithM value)
65+ , benchIOSrc serially "S.concatFoldableWith (<>) (List)"
66+ (concatFoldableWith value)
67+ , benchIOSrc serially "S.concatForFoldableWith (<>) (List)"
68+ (concatForFoldableWith value)
65 , benchIOSrc wAsyncly "foldMapM (List)" (sourceFoldMapM value)
69 , benchIOSrc wAsyncly "foldMapM (List)" (sourceFoldMapM value)
66 ]
70 ]
67 ]
71 ]
benchmark/lib/Streamly/Benchmark/Prelude.hs+18
@@ -23,6 +23,7 @@ import GHC.Exception (ErrorCall)
23import System.Random (randomRIO)
23import System.Random (randomRIO)
24
24
25import qualified Data.Foldable as F
25import qualified Data.Foldable as F
26+import qualified Data.List as List
26import qualified Streamly.Prelude as S
27import qualified Streamly.Prelude as S
27import qualified Streamly.Internal.Data.Stream.IsStream as Internal
28import qualified Streamly.Internal.Data.Stream.IsStream as Internal
28import qualified Streamly.Internal.Data.Pipe as Pipe
29import qualified Streamly.Internal.Data.Pipe as Pipe
@@ -287,6 +288,23 @@ sourceFoldMapWith :: (S.IsStream t, Semigroup (t m Int))
287 => Int -> Int -> t m Int
288 => Int -> Int -> t m Int
288sourceFoldMapWith value n = S.concatMapFoldableWith (<>) S.yield [n..n+value]
289sourceFoldMapWith value n = S.concatMapFoldableWith (<>) S.yield [n..n+value]
289
290
291+{-# INLINE concatForFoldableWith #-}
292+concatForFoldableWith :: (S.IsStream t, Semigroup (t m Int))
293+ => Int -> Int -> t m Int
294+concatForFoldableWith value n =
295+ S.concatForFoldableWith (<>) [n..n+value] S.yield
296+
297+{-# INLINE concatFoldableWith #-}
298+concatFoldableWith :: (S.IsStream t, Semigroup (t m Int))
299+ => Int -> Int -> t m Int
300+concatFoldableWith value n =
301+ let step x =
302+ if x <= n + value
303+ then Just (S.yield x, x + 1)
304+ else Nothing
305+ list = List.unfoldr step n
306+ in S.concatFoldableWith (<>) list
307+
290{-# INLINE sourceFoldMapWithStream #-}
308{-# INLINE sourceFoldMapWithStream #-}
291sourceFoldMapWithStream :: (S.IsStream t, Semigroup (t m Int))
309sourceFoldMapWithStream :: (S.IsStream t, Semigroup (t m Int))
292 => Int -> Int -> t m Int
310 => Int -> Int -> t m Int