on master help sign in
Add benchmarks for S.concatFoldableWith and S.concatForFoldableWith
commit06b230f27a9d119e8e42d740f58afcba318fcfd1 authoradithyaov <adithya@composewell.com> dateMon 23 Nov 2020, 13:36 (6 years ago) parentc7b7c2a
6 files changed+38
benchmark/Streamly/Benchmark/Prelude/Ahead.hs+4 benchmark/Streamly/Benchmark/Prelude/Async.hs+4 benchmark/Streamly/Benchmark/Prelude/Parallel.hs+4 benchmark/Streamly/Benchmark/Prelude/Serial.hs+4 benchmark/Streamly/Benchmark/Prelude/WAsync.hs+4 benchmark/lib/Streamly/Benchmark/Prelude.hs+18
benchmark/Streamly/Benchmark/Prelude/Ahead.hs+4
@@ -57,6 +57,10 @@ o_1_space_concatFoldable value =
5757 (sourceFoldMapWithStream value)
5858 , benchIOSrc aheadly "foldMapWithM (<>) (List)"
5959 (sourceFoldMapWithM value)
60+ , benchIOSrc serially "S.concatFoldableWith (<>) (List)"
61+ (concatFoldableWith value)
62+ , benchIOSrc serially "S.concatForFoldableWith (<>) (List)"
63+ (concatForFoldableWith value)
6064 , benchIOSrc aheadly "foldMapM (List)" (sourceFoldMapM value)
6165 ]
6266 ]
benchmark/Streamly/Benchmark/Prelude/Async.hs+4
@@ -114,6 +114,10 @@ o_1_space_concatFoldable value =
114114 (sourceFoldMapWithStream value)
115115 , benchIOSrc asyncly "foldMapWithM (<>) (List)"
116116 (sourceFoldMapWithM value)
117+ , benchIOSrc serially "S.concatFoldableWith (<>) (List)"
118+ (concatFoldableWith value)
119+ , benchIOSrc serially "S.concatForFoldableWith (<>) (List)"
120+ (concatForFoldableWith value)
117121 , benchIOSrc asyncly "foldMapM (List)" (sourceFoldMapM value)
118122 ]
119123 ]
benchmark/Streamly/Benchmark/Prelude/Parallel.hs+4
@@ -130,6 +130,10 @@ o_n_heap_concatFoldable value =
130130 (sourceFoldMapWithStream value)
131131 , benchIOSrc parallely "foldMapWithM (<>) (List)"
132132 (sourceFoldMapWithM value)
133+ , benchIOSrc serially "S.concatFoldableWith (<>) (List)"
134+ (concatFoldableWith value)
135+ , benchIOSrc serially "S.concatForFoldableWith (<>) (List)"
136+ (concatForFoldableWith value)
133137 , benchIOSrc parallely "foldMapM (List)" (sourceFoldMapM value)
134138 ]
135139 ]
benchmark/Streamly/Benchmark/Prelude/Serial.hs+4
@@ -1746,6 +1746,10 @@ o_1_space_concatFoldable value =
17461746 (sourceFoldMapWithStream value)
17471747 , benchIOSrc serially "foldMapWithM (<>) (List)"
17481748 (sourceFoldMapWithM value)
1749+ , benchIOSrc serially "S.concatFoldableWith (<>) (List)"
1750+ (concatFoldableWith value)
1751+ , benchIOSrc serially "S.concatForFoldableWith (<>) (List)"
1752+ (concatForFoldableWith value)
17491753 , benchIOSrc serially "foldMapM (List)" (sourceFoldMapM value)
17501754 ]
17511755 ]
benchmark/Streamly/Benchmark/Prelude/WAsync.hs+4
@@ -62,6 +62,10 @@ o_1_space_concatFoldable value =
6262 (sourceFoldMapWithStream value)
6363 , benchIOSrc wAsyncly "foldMapWithM (<>) (List)"
6464 (sourceFoldMapWithM value)
65+ , benchIOSrc serially "S.concatFoldableWith (<>) (List)"
66+ (concatFoldableWith value)
67+ , benchIOSrc serially "S.concatForFoldableWith (<>) (List)"
68+ (concatForFoldableWith value)
6569 , benchIOSrc wAsyncly "foldMapM (List)" (sourceFoldMapM value)
6670 ]
6771 ]
benchmark/lib/Streamly/Benchmark/Prelude.hs+18
@@ -23,6 +23,7 @@ import GHC.Exception (ErrorCall)
2323import System.Random (randomRIO)
2424
2525import qualified Data.Foldable as F
26+import qualified Data.List as List
2627import qualified Streamly.Prelude as S
2728import qualified Streamly.Internal.Data.Stream.IsStream as Internal
2829import qualified Streamly.Internal.Data.Pipe as Pipe
@@ -287,6 +288,23 @@ sourceFoldMapWith :: (S.IsStream t, Semigroup (t m Int))
287288 => Int -> Int -> t m Int
288289sourceFoldMapWith value n = S.concatMapFoldableWith (<>) S.yield [n..n+value]
289290
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+
290308{-# INLINE sourceFoldMapWithStream #-}
291309sourceFoldMapWithStream :: (S.IsStream t, Semigroup (t m Int))
292310 => Int -> Int -> t m Int