on master help sign in
merge nested and nested-unfold benchmarks with others

merge them with other serial stream benchmarks.

commit7ce2dc87ea7b991a00b4dbf75fc61993d82b03e5 authorHarendra Kumar <harendra.kumar@gmail.com> dateWed 19 Feb 2020, 03:49 (7 years ago) parent0b00efe
5 files changed+90−144
benchmark/Nested.hs−61 benchmark/NestedUnfold.hs−38 benchmark/Streamly/Benchmark/Prelude/Serial/O_1_Space.hs+70−31 benchmark/Streamly/Benchmark/Prelude/Serial/O_n_Space.hs+18 benchmark/streamly-benchmarks.cabal+2−14
benchmark/Nested.hsdeleted−61
@@ -1,61 +0,0 @@
1−-- |
2−-- Module : Main
3−-- Copyright : (c) 2018 Harendra Kumar
4−--
5−-- License : BSD3
6−-- Maintainer : streamly@composewell.com
7−
8−import Control.DeepSeq (NFData)
9−import Data.Functor.Identity (Identity, runIdentity)
10−import System.Random (randomRIO)
11−
12−import Streamly.Benchmark.Common (parseCLIOpts)
13−
14−import Streamly
15−import Gauge
16−
17−import qualified NestedOps as Ops
18−
19−benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
20−benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
21−
22−_benchId :: (NFData b) => String -> (Int -> Identity b) -> Benchmark
23−_benchId name f = bench name $ nf (\g -> runIdentity (g 1)) f
24−
25−defaultStreamSize :: Int
26−defaultStreamSize = 100000
27−
28−main :: IO ()
29−main = do
30− -- XXX Fix indentation
31− (linearCount, cfg, benches) <- parseCLIOpts defaultStreamSize
32− linearCount `seq` runMode (mode cfg) cfg benches
33− [ bgroup "serially"
34− [ benchIO "toNullAp" $ Ops.toNullAp linearCount serially
35− , benchIO "toNull" $ Ops.toNull linearCount serially
36− , benchIO "toNull3" $ Ops.toNull3 linearCount serially
37− -- , benchIO "toList" $ Ops.toList linearCount serially
38− -- XXX takes too much stack space
39− , benchIO "toListSome" $ Ops.toListSome linearCount serially
40− , benchIO "filterAllOut" $ Ops.filterAllOut linearCount serially
41− , benchIO "filterAllIn" $ Ops.filterAllIn linearCount serially
42− , benchIO "filterSome" $ Ops.filterSome linearCount serially
43− , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount serially
44− ]
45−
46− , bgroup "wSerially"
47− [ benchIO "toNullAp" $ Ops.toNullAp linearCount wSerially
48− , benchIO "toNull" $ Ops.toNull linearCount wSerially
49− , benchIO "toNull3" $ Ops.toNull3 linearCount wSerially
50− -- , benchIO "toList" $ Ops.toList linearCount wSerially
51− , benchIO "toListSome" $ Ops.toListSome linearCount wSerially
52− , benchIO "filterAllOut" $ Ops.filterAllOut linearCount wSerially
53− , benchIO "filterAllIn" $ Ops.filterAllIn linearCount wSerially
54− , benchIO "filterSome" $ Ops.filterSome linearCount wSerially
55− , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount wSerially
56− ]
57−
58− , bgroup "zipSerially"
59− [ benchIO "toNullAp" $ Ops.toNullAp linearCount zipSerially
60− ]
61− ]
benchmark/NestedUnfold.hsdeleted−38
@@ -1,38 +0,0 @@
1−-- |
2−-- Module : NestedUnfold
3−-- Copyright : (c) 2019 Composewell Technologies
4−--
5−-- License : BSD3
6−-- Maintainer : streamly@composewell.com
7−
8−import Control.DeepSeq (NFData)
9−import System.Random (randomRIO)
10−
11−import Streamly.Benchmark.Common (parseCLIOpts)
12−
13−import qualified NestedUnfoldOps as Ops
14−
15−import Gauge
16−
17−benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
18−benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
19−
20−defaultStreamSize :: Int
21−defaultStreamSize = 100000
22−
23−main :: IO ()
24−main = do
25− (linearCount, cfg, benches) <- parseCLIOpts defaultStreamSize
26− linearCount `seq` runMode (mode cfg) cfg benches
27− [ bgroup "unfold"
28− [ benchIO "toNull" $ Ops.toNull linearCount
29− , benchIO "toNull3" $ Ops.toNull3 linearCount
30− , benchIO "concat" $ Ops.concat linearCount
31− -- , benchIO "toList" $ Ops.toList
32− , benchIO "toListSome" $ Ops.toListSome linearCount
33− , benchIO "filterAllOut" $ Ops.filterAllOut linearCount
34− , benchIO "filterAllIn" $ Ops.filterAllIn linearCount
35− , benchIO "filterSome" $ Ops.filterSome linearCount
36− , benchIO "breakAfterSome" $ Ops.breakAfterSome linearCount
37− ]
38− ]
benchmark/Streamly/Benchmark/Prelude/Serial/O_1_Space.hs+70−31
@@ -24,6 +24,9 @@ import qualified Streamly.Internal.Data.Fold as IFL
2424import qualified Streamly.Internal.Prelude as IP
2525import qualified Streamly.Internal.Data.Pipe as Pipe
2626
27+import qualified NestedOps as Nested
28+import qualified NestedUnfoldOps as NestedUnfold
29+
2730import Gauge
2831import Streamly.Benchmark.Common
2932
@@ -70,6 +73,9 @@ benchIOSrc t name f =
7073benchPureSink :: NFData b => Int -> String -> (SerialT Identity Int -> b) -> Benchmark
7174benchPureSink value name f = benchPure name (Ops.sourceUnfoldr value) f
7275
76+benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
77+benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
78+
7379-------------------------------------------------------------------------------
7480--
7581-------------------------------------------------------------------------------
@@ -392,43 +398,76 @@ main = do
392398 , benchIOSrc1 "concatMapWithAppend (2,x/2)"
393399 (Ops.concatMapWithAppend 2 (value `div` 2))
394400 ]
395− , bgroup "concat-interleave"
401+ , bgroup "outer-product-streams"
402+ [ benchIO "toNullAp" $ Nested.toNullAp value serially
403+ , benchIO "toNull" $ Nested.toNull value serially
404+ , benchIO "toNull3" $ Nested.toNull3 value serially
405+ , benchIO "filterAllOut" $ Nested.filterAllOut value serially
406+ , benchIO "filterAllIn" $ Nested.filterAllIn value serially
407+ , benchIO "filterSome" $ Nested.filterSome value serially
408+ , benchIO "breakAfterSome" $ Nested.breakAfterSome value serially
409+ ]
410+ , bgroup "outer-product-unfolds"
411+ [ benchIO "toNull" $ NestedUnfold.toNull value
412+ , benchIO "toNull3" $ NestedUnfold.toNull3 value
413+ , benchIO "concat" $ NestedUnfold.concat value
414+ , benchIO "filterAllOut" $ NestedUnfold.filterAllOut value
415+ , benchIO "filterAllIn" $ NestedUnfold.filterAllIn value
416+ , benchIO "filterSome" $ NestedUnfold.filterSome value
417+ , benchIO "breakAfterSome" $ NestedUnfold.breakAfterSome value
418+ ]
419+ -- scanl-map and foldl-map are equivalent to the scan and fold in the foldl
420+ -- library. If scan/fold followed by a map is efficient enough we may not
421+ -- need monolithic implementations of these.
422+ , bgroup "mixed"
423+ [ benchIOSink value "scanl-map" (Ops.scanMap 1)
424+ , benchIOSink value "foldl-map" Ops.foldl'ReduceMap
425+ , benchIOSink value "sum-product-fold" Ops.sumProductFold
426+ , benchIOSink value "sum-product-scan" Ops.sumProductScan
427+ ]
428+ , bgroup "mixedX4"
429+ [ benchIOSink value "scan-map" (Ops.scanMap 4)
430+ , benchIOSink value "drop-map" (Ops.dropMap 4)
431+ , benchIOSink value "drop-scan" (Ops.dropScan 4)
432+ , benchIOSink value "take-drop" (Ops.takeDrop value 4)
433+ , benchIOSink value "take-scan" (Ops.takeScan value 4)
434+ , benchIOSink value "take-map" (Ops.takeMap value 4)
435+ , benchIOSink value "filter-drop" (Ops.filterDrop value 4)
436+ , benchIOSink value "filter-take" (Ops.filterTake value 4)
437+ , benchIOSink value "filter-scan" (Ops.filterScan 4)
438+ , benchIOSink value "filter-scanl1" (Ops.filterScanl1 4)
439+ , benchIOSink value "filter-map" (Ops.filterMap value 4)
440+ ]
441+ ]
442+ , bgroup "wSerially"
443+ [ bgroup "transformation"
444+ [ benchIOSink value "fmap" $ Ops.fmap' wSerially 1
445+ ]
446+ , bgroup "concatMap"
396447 [ benchIOSrc1 "concatMapWithWSerial (2,x/2)"
397448 (Ops.concatMapWithWSerial 2 (value `div` 2))
398449 , benchIOSrc1 "concatMapWithWSerial (x/2,2)"
399450 (Ops.concatMapWithWSerial (value `div` 2) 2)
400451 ]
401− -- scanl-map and foldl-map are equivalent to the scan and fold in the foldl
402− -- library. If scan/fold followed by a map is efficient enough we may not
403− -- need monolithic implementations of these.
404− , bgroup "mixed"
405− [ benchIOSink value "scanl-map" (Ops.scanMap 1)
406− , benchIOSink value "foldl-map" Ops.foldl'ReduceMap
407− , benchIOSink value "sum-product-fold" Ops.sumProductFold
408− , benchIOSink value "sum-product-scan" Ops.sumProductScan
409− ]
410− , bgroup "mixedX4"
411− [ benchIOSink value "scan-map" (Ops.scanMap 4)
412− , benchIOSink value "drop-map" (Ops.dropMap 4)
413− , benchIOSink value "drop-scan" (Ops.dropScan 4)
414− , benchIOSink value "take-drop" (Ops.takeDrop value 4)
415− , benchIOSink value "take-scan" (Ops.takeScan value 4)
416− , benchIOSink value "take-map" (Ops.takeMap value 4)
417− , benchIOSink value "filter-drop" (Ops.filterDrop value 4)
418− , benchIOSink value "filter-take" (Ops.filterTake value 4)
419− , benchIOSink value "filter-scan" (Ops.filterScan 4)
420− , benchIOSink value "filter-scanl1" (Ops.filterScanl1 4)
421− , benchIOSink value "filter-map" (Ops.filterMap value 4)
422− ]
423− ]
424− , bgroup "wSerially"
425− [ bgroup "transformation"
426− [ benchIOSink value "fmap" $ Ops.fmap' wSerially 1
427− ]
452+ , bgroup "outer-product"
453+ [ benchIO "toNullAp" $ Nested.toNullAp value wSerially
454+ , benchIO "toNull" $ Nested.toNull value wSerially
455+ , benchIO "toNull3" $ Nested.toNull3 value wSerially
456+ , benchIO "filterAllOut" $ Nested.filterAllOut value wSerially
457+ , benchIO "filterAllIn" $ Nested.filterAllIn value wSerially
458+ , benchIO "filterSome" $ Nested.filterSome value wSerially
459+ , benchIO "breakAfterSome" $ Nested.breakAfterSome value wSerially
428460 ]
461+ ]
429462 , bgroup "zipSerially"
430− [ bgroup "transformation"
431− [ benchIOSink value "fmap" $ Ops.fmap' zipSerially 1
432− ]
463+ [ bgroup "transformation"
464+ [ benchIOSink value "fmap" $ Ops.fmap' zipSerially 1
433465 ]
466+ -- XXX needs fixing
467+ {-
468+ , bgroup "outer-product"
469+ [ benchIO "toNullAp" $ Nested.toNullAp value zipSerially
470+ ]
471+ -}
472+ ]
434473 ]
benchmark/Streamly/Benchmark/Prelude/Serial/O_n_Space.hs+18
@@ -11,6 +11,9 @@ import System.Random (randomRIO)
1111
1212import qualified Streamly.Benchmark.Prelude as Ops
1313
14+import qualified NestedOps as Nested
15+import qualified NestedUnfoldOps as NestedUnfold
16+
1417import Streamly
1518import Gauge
1619import Streamly.Benchmark.Common
@@ -49,6 +52,9 @@ benchPureSinkIO
4952benchPureSinkIO value name f =
5053 bench name $ nfIO $ randomRIO (1, 1) >>= f . Ops.sourceUnfoldr value
5154
55+benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
56+benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
57+
5258-------------------------------------------------------------------------------
5359-- Benchmarks
5460-------------------------------------------------------------------------------
@@ -72,6 +78,18 @@ main = do
7278 -- , benchIOSink size "toPure" Ops.toPure
7379 -- , benchIOSink size "toPureRev" Ops.toPureRev
7480 ]
81+ , bgroup "outer-product-streams"
82+ [ benchIO "toList" $ Nested.toList size serially
83+ , benchIO "toListSome" $ Nested.toListSome size serially
84+ ]
85+ , bgroup "outer-product-unfolds"
86+ [ benchIO "toList" $ NestedUnfold.toList size
87+ , benchIO "toListSome" $ NestedUnfold.toListSome size
88+ ]
89+ , bgroup "outer-product-wserial"
90+ [ benchIO "toList" $ Nested.toList size wSerially
91+ , benchIO "toListSome" $ Nested.toListSome size wSerially
92+ ]
7593 -- Buffering operations using heap proportional to number of elements.
7694 , bgroup "traversable" -- < 2MB
7795 [ -- Traversable instance
benchmark/streamly-benchmarks.cabal+2−14
@@ -166,6 +166,7 @@ benchmark linear
166166 type: exitcode-stdio-1.0
167167 ghc-options: -with-rtsopts "-T -K36K -M16M"
168168 main-is: Streamly/Benchmark/Prelude/Serial/O_1_Space.hs
169+ other-modules: NestedOps, NestedUnfoldOps
169170
170171benchmark serial-O-n-heap
171172 import: bench-options
@@ -184,20 +185,7 @@ benchmark serial-O-n-space
184185 type: exitcode-stdio-1.0
185186 ghc-options: -with-rtsopts "-T -K16M -M64M"
186187 main-is: Streamly/Benchmark/Prelude/Serial/O_n_Space.hs
187−
188−benchmark nested
189− import: bench-options
190− type: exitcode-stdio-1.0
191− ghc-options: -with-rtsopts "-T -K256K -M16M"
192− main-is: Nested.hs
193− other-modules: NestedOps
194−
195−benchmark nested-unfold
196− import: bench-options
197− type: exitcode-stdio-1.0
198− ghc-options: -with-rtsopts "-T -K64K -M16M"
199− main-is: NestedUnfold.hs
200− other-modules: NestedUnfoldOps
188+ other-modules: NestedOps, NestedUnfoldOps
201189
202190benchmark base
203191 import: bench-options