on master help sign in
Add async interleave benchmarks
commit888d1afbb738773dae36333e828a5c52c0514f48 authorHarendra Kumar <harendra@composewell.com> dateWed 21 Sep 2022, 00:56 (4 years ago) parent2ca80e7
1 file changed+31
benchmark/Streamly/Benchmark/Data/Stream/Async.hs+31
benchmark/Streamly/Benchmark/Data/Stream/Async.hs+31
@@ -65,10 +65,24 @@ async2 count n =
6565 Stream.fold Fold.drain $
6666 sourceUnfoldrM count n `Async.append` sourceUnfoldrM count (n + 1)
6767
68+{-# INLINE concatAsync2 #-}
69+concatAsync2 :: Int -> Int -> IO ()
70+concatAsync2 count n =
71+ Stream.fold Fold.drain $
72+ Async.concatList [sourceUnfoldrM count n, sourceUnfoldrM count (n + 1)]
73+
74+{-# INLINE interleave2 #-}
75+interleave2 :: Int -> Int -> IO ()
76+interleave2 count n =
77+ Stream.fold Fold.drain $
78+ sourceUnfoldrM count n `Async.interleave` sourceUnfoldrM count (n + 1)
79+
6880o_1_space_joining :: Int -> [Benchmark]
6981o_1_space_joining value =
7082 [ bgroup "joining"
7183 [ benchIOSrc1 "async (2 of n/2)" (async2 (value `div` 2))
84+ , benchIOSrc1 "concat async (2 of n/2)" (concatAsync2 (value `div` 2))
85+ , benchIOSrc1 "interleave (2 of n/2)" (interleave2 (value `div` 2))
7286 ]
7387 ]
7488
@@ -129,6 +143,17 @@ concatFmapStreamsWith outer inner n =
129143 $ Async.concat
130144 $ fmap (sourceUnfoldrM inner) (sourceUnfoldrM outer n)
131145
146+{-# INLINE concatMapInterleaveStreamsWith #-}
147+concatMapInterleaveStreamsWith
148+ :: Int
149+ -> Int
150+ -> Int
151+ -> IO ()
152+concatMapInterleaveStreamsWith outer inner n =
153+ Stream.fold Fold.drain
154+ $ Async.concatMapInterleave
155+ (sourceUnfoldrM inner) (sourceUnfoldrM outer n)
156+
132157o_1_space_concatMap :: Int -> [Benchmark]
133158o_1_space_concatMap value =
134159 value2 `seq`
@@ -141,6 +166,12 @@ o_1_space_concatMap value =
141166 (concatMapStreamsWith 1 value)
142167 , benchIO "concat . fmap (n of 1)"
143168 (concatFmapStreamsWith value 1)
169+ , benchIO "concatMapInterleaveWith (n of 1)"
170+ (concatMapInterleaveStreamsWith value 1)
171+ , benchIO "concatMapInterleaveWith (sqrt x of sqrt x)"
172+ (concatMapInterleaveStreamsWith value2 value2)
173+ , benchIO "concatMapInterleaveWith (1 of n)"
174+ (concatMapInterleaveStreamsWith 1 value)
144175 ]
145176 ]
146177