on master help sign in
Add async interleave benchmarks
888d1afHarendra Kumar
benchmark/Streamly/Benchmark/Data/Stream/Async.hs+31
@@ -65,10 +65,24 @@ async2 count n =
65 Stream.fold Fold.drain $
65 Stream.fold Fold.drain $
66 sourceUnfoldrM count n `Async.append` sourceUnfoldrM count (n + 1)
66 sourceUnfoldrM count n `Async.append` sourceUnfoldrM count (n + 1)
67
67
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+
68o_1_space_joining :: Int -> [Benchmark]
80o_1_space_joining :: Int -> [Benchmark]
69o_1_space_joining value =
81o_1_space_joining value =
70 [ bgroup "joining"
82 [ bgroup "joining"
71 [ benchIOSrc1 "async (2 of n/2)" (async2 (value `div` 2))
83 [ 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))
72 ]
86 ]
73 ]
87 ]
74
88
@@ -129,6 +143,17 @@ concatFmapStreamsWith outer inner n =
129 $ Async.concat
143 $ Async.concat
130 $ fmap (sourceUnfoldrM inner) (sourceUnfoldrM outer n)
144 $ fmap (sourceUnfoldrM inner) (sourceUnfoldrM outer n)
131
145
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+
132o_1_space_concatMap :: Int -> [Benchmark]
157o_1_space_concatMap :: Int -> [Benchmark]
133o_1_space_concatMap value =
158o_1_space_concatMap value =
134 value2 `seq`
159 value2 `seq`
@@ -141,6 +166,12 @@ o_1_space_concatMap value =
141 (concatMapStreamsWith 1 value)
166 (concatMapStreamsWith 1 value)
142 , benchIO "concat . fmap (n of 1)"
167 , benchIO "concat . fmap (n of 1)"
143 (concatFmapStreamsWith value 1)
168 (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)
144 ]
175 ]
145 ]
176 ]
146
177