on master help sign in
Separate interleaved benchmarks in another module
162fc17Harendra Kumar
benchmark/Streamly/Benchmark/Data/Stream/Async.hs+2−7
@@ -6,7 +6,7 @@
6-- License : BSD3
6-- License : BSD3
7-- Maintainer : streamly@composewell.com
7-- Maintainer : streamly@composewell.com
8
8
9−import Stream.AsyncCommon (allBenchmarks, interleaveBenchmarks)
9+import Stream.AsyncCommon (allBenchmarks)
10import Streamly.Benchmark.Common (runWithCLIOpts, defaultStreamSize)
10import Streamly.Benchmark.Common (runWithCLIOpts, defaultStreamSize)
11
11
12moduleName :: String
12moduleName :: String
@@ -17,9 +17,4 @@ moduleName = "Data.Stream.Concurrent"
17-------------------------------------------------------------------------------
17-------------------------------------------------------------------------------
18
18
19main :: IO ()
19main :: IO ()
20−main =
21− runWithCLIOpts defaultStreamSize
20+main = runWithCLIOpts defaultStreamSize (allBenchmarks moduleName id)
22− (\value ->
23− allBenchmarks moduleName id value
24− <> interleaveBenchmarks moduleName id value
25− )
benchmark/Streamly/Benchmark/Data/Stream/AsyncCommon.hs−46
@@ -8,7 +8,6 @@
8
8
9module Stream.AsyncCommon
9module Stream.AsyncCommon
10 ( allBenchmarks
10 ( allBenchmarks
11− , interleaveBenchmarks
12 )
11 )
13where
12where
14
13
@@ -80,19 +79,11 @@ concatAsync2 f count n =
80 $ Stream.fromList
79 $ Stream.fromList
81 [sourceUnfoldrM count n, sourceUnfoldrM count (n + 1)]
80 [sourceUnfoldrM count n, sourceUnfoldrM count (n + 1)]
82
81
83−{-# INLINE interleave2 #-}
84−interleave2 :: (Config -> Config) -> Int -> Int -> IO ()
85−interleave2 f count n =
86− Stream.fold Fold.drain
87− $ Async.combineWith (f . Async.interleaved)
88− (sourceUnfoldrM count n) (sourceUnfoldrM count (n + 1))
89−
90o_1_space_joining :: Int -> (Config -> Config) -> [Benchmark]
82o_1_space_joining :: Int -> (Config -> Config) -> [Benchmark]
91o_1_space_joining value f =
83o_1_space_joining value f =
92 [ bgroup "joining"
84 [ bgroup "joining"
93 [ benchIOSrc1 "async (2 of n/2)" (async2 f (value `div` 2))
85 [ benchIOSrc1 "async (2 of n/2)" (async2 f (value `div` 2))
94 , benchIOSrc1 "concat async (2 of n/2)" (concatAsync2 f (value `div` 2))
86 , benchIOSrc1 "concat async (2 of n/2)" (concatAsync2 f (value `div` 2))
95− , benchIOSrc1 "interleave (2 of n/2)" (interleave2 f (value `div` 2))
96 ]
87 ]
97 ]
88 ]
98
89
@@ -156,18 +147,6 @@ concatFmapStreamsWith f outer inner n =
156 $ Async.concatWith f
147 $ Async.concatWith f
157 $ fmap (sourceUnfoldrM inner) (sourceUnfoldrM outer n)
148 $ fmap (sourceUnfoldrM inner) (sourceUnfoldrM outer n)
158
149
159−{-# INLINE concatMapInterleaveStreamsWith #-}
160−concatMapInterleaveStreamsWith
161− :: (Config -> Config)
162− -> Int
163− -> Int
164− -> Int
165− -> IO ()
166−concatMapInterleaveStreamsWith f outer inner n =
167− Stream.fold Fold.drain
168− $ Async.concatMapWith (f . Async.interleaved)
169− (sourceUnfoldrM inner) (sourceUnfoldrM outer n)
170−
171o_1_space_concatMap :: Int -> (Config -> Config) -> [Benchmark]
150o_1_space_concatMap :: Int -> (Config -> Config) -> [Benchmark]
172o_1_space_concatMap value f =
151o_1_space_concatMap value f =
173 value2 `seq`
152 value2 `seq`
@@ -187,24 +166,6 @@ o_1_space_concatMap value f =
187
166
188 value2 = round $ sqrt (fromIntegral value :: Double)
167 value2 = round $ sqrt (fromIntegral value :: Double)
189
168
190−-- XXX These do not work with the eager option
191−o_1_space_concatMapInterleave :: Int -> (Config -> Config) -> [Benchmark]
192−o_1_space_concatMapInterleave value f =
193− value2 `seq`
194− [ bgroup "concat"
195− [ benchIO "concatMapInterleaveWith (n of 1)"
196− (concatMapInterleaveStreamsWith f value 1)
197− , benchIO "concatMapInterleaveWith (sqrt x of sqrt x)"
198− (concatMapInterleaveStreamsWith f value2 value2)
199− , benchIO "concatMapInterleaveWith (1 of n)"
200− (concatMapInterleaveStreamsWith f 1 value)
201− ]
202− ]
203−
204− where
205−
206− value2 = round $ sqrt (fromIntegral value :: Double)
207−
208-------------------------------------------------------------------------------
169-------------------------------------------------------------------------------
209-- Monadic outer product
170-- Monadic outer product
210-------------------------------------------------------------------------------
171-------------------------------------------------------------------------------
@@ -244,10 +205,3 @@ allBenchmarks moduleName modifier value =
244 , bgroup (o_n_heap_prefix moduleName)
205 , bgroup (o_n_heap_prefix moduleName)
245 (o_n_heap_buffering value modifier)
206 (o_n_heap_buffering value modifier)
246 ]
207 ]
247−
248−interleaveBenchmarks :: String -> (Config -> Config) -> Int -> [Benchmark]
249−interleaveBenchmarks moduleName modifier value =
250− [ bgroup
251− (o_1_space_prefix moduleName)
252− (o_1_space_concatMapInterleave value modifier)
253− ]
benchmark/Streamly/Benchmark/Data/Stream/ConcurrentEager.hs+1−2
@@ -19,5 +19,4 @@ moduleName = "Data.Stream.ConcurrentEager"
19-------------------------------------------------------------------------------
19-------------------------------------------------------------------------------
20
20
21main :: IO ()
21main :: IO ()
22−main =
23− runWithCLIOpts defaultStreamSize (allBenchmarks moduleName Async.eager)
22+main = runWithCLIOpts defaultStreamSize (allBenchmarks moduleName Async.eager)
benchmark/Streamly/Benchmark/Data/Stream/ConcurrentInterleaved.hsnew file+24
@@ -0,0 +1,24 @@
1+{-# LANGUAGE FlexibleContexts #-}
2+-- |
3+-- Module : Main
4+-- Copyright : (c) 2022 Composewell Technologies
5+--
6+-- License : BSD3
7+-- Maintainer : streamly@composewell.com
8+
9+import Stream.AsyncCommon (allBenchmarks)
10+import Streamly.Benchmark.Common (runWithCLIOpts, defaultStreamSize)
11+
12+import qualified Streamly.Internal.Data.Stream.Concurrent as Async
13+
14+moduleName :: String
15+moduleName = "Data.Stream.ConcurrentInterleaved"
16+
17+-------------------------------------------------------------------------------
18+-- Main
19+-------------------------------------------------------------------------------
20+
21+main :: IO ()
22+main =
23+ runWithCLIOpts
24+ defaultStreamSize (allBenchmarks moduleName Async.interleaved)
benchmark/bench-runner/Main.hs+1
@@ -51,6 +51,7 @@ rtsOpts exeName benchName0 = unwords [general, exeSpecific, benchSpecific]
51 "-K8M -M64M"
51 "-K8M -M64M"
52 | "Data.Stream/o-n-space.grouping." `isPrefixOf` benchName = ""
52 | "Data.Stream/o-n-space.grouping." `isPrefixOf` benchName = ""
53 | "Data.Stream/o-n-space." `isPrefixOf` benchName = "-K4M"
53 | "Data.Stream/o-n-space." `isPrefixOf` benchName = "-K4M"
54+ | "Data.Stream.ConcurrentInterleaved/o-1-space.monad-outer-product.toNullAp" `isPrefixOf` benchName = "-M32M"
54 | "Data.Stream.ConcurrentEager/o-1-space.monad-outer-product.toNullAp" `isPrefixOf` benchName = "-M1024M -K4M"
55 | "Data.Stream.ConcurrentEager/o-1-space.monad-outer-product.toNullAp" `isPrefixOf` benchName = "-M1024M -K4M"
55 | "Data.Stream.ConcurrentEager/o-1-space." `isPrefixOf` benchName = "-M512M -K4M"
56 | "Data.Stream.ConcurrentEager/o-1-space." `isPrefixOf` benchName = "-M512M -K4M"
56 | "Prelude.WSerial/o-n-space." `isPrefixOf` benchName = "-K4M"
57 | "Prelude.WSerial/o-n-space." `isPrefixOf` benchName = "-K4M"
benchmark/streamly-benchmarks.cabal+13
@@ -257,6 +257,19 @@ benchmark Data.Stream.Async
257 else
257 else
258 buildable: True
258 buildable: True
259
259
260+benchmark Data.Stream.ConcurrentInterleaved
261+ import: bench-options-threaded
262+ type: exitcode-stdio-1.0
263+ hs-source-dirs: Streamly/Benchmark/Data/Stream/, Streamly/Benchmark/Data/
264+ main-is: ConcurrentInterleaved.hs
265+ other-modules:
266+ Stream.AsyncCommon
267+ Stream.Common
268+ if flag(use-streamly-core) || impl(ghcjs)
269+ buildable: False
270+ else
271+ buildable: True
272+
260benchmark Data.Stream.ConcurrentEager
273benchmark Data.Stream.ConcurrentEager
261 import: bench-options-threaded
274 import: bench-options-threaded
262 type: exitcode-stdio-1.0
275 type: exitcode-stdio-1.0
targets/Targets.hs+6
@@ -46,6 +46,12 @@ targets =
46 , "concurrent_cmp"
46 , "concurrent_cmp"
47 ]
47 ]
48 )
48 )
49+ , ("Data.Stream.ConcurrentInterleaved",
50+ [ "prelude_concurrent_grp"
51+ , "infinite_grp"
52+ , "concurrent_cmp"
53+ ]
54+ )
49 , ("Prelude.WSerial", ["serial_wserial_cmp"])
55 , ("Prelude.WSerial", ["serial_wserial_cmp"])
50 , ("Prelude.WSerial",
56 , ("Prelude.WSerial",
51 [ "prelude_serial_grp"
57 [ "prelude_serial_grp"