on master help sign in
merge nested and nested-unfold benchmarks with others
7ce2dc8Harendra Kumar
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
24import qualified Streamly.Internal.Prelude as IP
24import qualified Streamly.Internal.Prelude as IP
25import qualified Streamly.Internal.Data.Pipe as Pipe
25import qualified Streamly.Internal.Data.Pipe as Pipe
26
26
27+import qualified NestedOps as Nested
28+import qualified NestedUnfoldOps as NestedUnfold
29+
27import Gauge
30import Gauge
28import Streamly.Benchmark.Common
31import Streamly.Benchmark.Common
29
32
@@ -70,6 +73,9 @@ benchIOSrc t name f =
70benchPureSink :: NFData b => Int -> String -> (SerialT Identity Int -> b) -> Benchmark
73benchPureSink :: NFData b => Int -> String -> (SerialT Identity Int -> b) -> Benchmark
71benchPureSink value name f = benchPure name (Ops.sourceUnfoldr value) f
74benchPureSink value name f = benchPure name (Ops.sourceUnfoldr value) f
72
75
76+benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
77+benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
78+
73-------------------------------------------------------------------------------
79-------------------------------------------------------------------------------
74--
80--
75-------------------------------------------------------------------------------
81-------------------------------------------------------------------------------
@@ -392,43 +398,76 @@ main = do
392 , benchIOSrc1 "concatMapWithAppend (2,x/2)"
398 , benchIOSrc1 "concatMapWithAppend (2,x/2)"
393 (Ops.concatMapWithAppend 2 (value `div` 2))
399 (Ops.concatMapWithAppend 2 (value `div` 2))
394 ]
400 ]
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"
396 [ benchIOSrc1 "concatMapWithWSerial (2,x/2)"
447 [ benchIOSrc1 "concatMapWithWSerial (2,x/2)"
397 (Ops.concatMapWithWSerial 2 (value `div` 2))
448 (Ops.concatMapWithWSerial 2 (value `div` 2))
398 , benchIOSrc1 "concatMapWithWSerial (x/2,2)"
449 , benchIOSrc1 "concatMapWithWSerial (x/2,2)"
399 (Ops.concatMapWithWSerial (value `div` 2) 2)
450 (Ops.concatMapWithWSerial (value `div` 2) 2)
400 ]
451 ]
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"
452+ , bgroup "outer-product"
405− [ benchIOSink value "scanl-map" (Ops.scanMap 1)
453+ [ benchIO "toNullAp" $ Nested.toNullAp value wSerially
406− , benchIOSink value "foldl-map" Ops.foldl'ReduceMap
454+ , benchIO "toNull" $ Nested.toNull value wSerially
407− , benchIOSink value "sum-product-fold" Ops.sumProductFold
455+ , benchIO "toNull3" $ Nested.toNull3 value wSerially
408− , benchIOSink value "sum-product-scan" Ops.sumProductScan
456+ , benchIO "filterAllOut" $ Nested.filterAllOut value wSerially
409− ]
457+ , benchIO "filterAllIn" $ Nested.filterAllIn value wSerially
410− , bgroup "mixedX4"
458+ , benchIO "filterSome" $ Nested.filterSome value wSerially
411− [ benchIOSink value "scan-map" (Ops.scanMap 4)
459+ , benchIO "breakAfterSome" $ Nested.breakAfterSome value wSerially
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− ]
428 ]
460 ]
461+ ]
429 , bgroup "zipSerially"
462 , bgroup "zipSerially"
430− [ bgroup "transformation"
463+ [ bgroup "transformation"
431− [ benchIOSink value "fmap" $ Ops.fmap' zipSerially 1
464+ [ benchIOSink value "fmap" $ Ops.fmap' zipSerially 1
432− ]
433 ]
465 ]
466+ -- XXX needs fixing
467+ {-
468+ , bgroup "outer-product"
469+ [ benchIO "toNullAp" $ Nested.toNullAp value zipSerially
470+ ]
471+ -}
472+ ]
434 ]
473 ]
benchmark/Streamly/Benchmark/Prelude/Serial/O_n_Space.hs+18
@@ -11,6 +11,9 @@ import System.Random (randomRIO)
11
11
12import qualified Streamly.Benchmark.Prelude as Ops
12import qualified Streamly.Benchmark.Prelude as Ops
13
13
14+import qualified NestedOps as Nested
15+import qualified NestedUnfoldOps as NestedUnfold
16+
14import Streamly
17import Streamly
15import Gauge
18import Gauge
16import Streamly.Benchmark.Common
19import Streamly.Benchmark.Common
@@ -49,6 +52,9 @@ benchPureSinkIO
49benchPureSinkIO value name f =
52benchPureSinkIO value name f =
50 bench name $ nfIO $ randomRIO (1, 1) >>= f . Ops.sourceUnfoldr value
53 bench name $ nfIO $ randomRIO (1, 1) >>= f . Ops.sourceUnfoldr value
51
54
55+benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
56+benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
57+
52-------------------------------------------------------------------------------
58-------------------------------------------------------------------------------
53-- Benchmarks
59-- Benchmarks
54-------------------------------------------------------------------------------
60-------------------------------------------------------------------------------
@@ -72,6 +78,18 @@ main = do
72 -- , benchIOSink size "toPure" Ops.toPure
78 -- , benchIOSink size "toPure" Ops.toPure
73 -- , benchIOSink size "toPureRev" Ops.toPureRev
79 -- , benchIOSink size "toPureRev" Ops.toPureRev
74 ]
80 ]
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+ ]
75 -- Buffering operations using heap proportional to number of elements.
93 -- Buffering operations using heap proportional to number of elements.
76 , bgroup "traversable" -- < 2MB
94 , bgroup "traversable" -- < 2MB
77 [ -- Traversable instance
95 [ -- Traversable instance
benchmark/streamly-benchmarks.cabal+2−14
@@ -166,6 +166,7 @@ benchmark linear
166 type: exitcode-stdio-1.0
166 type: exitcode-stdio-1.0
167 ghc-options: -with-rtsopts "-T -K36K -M16M"
167 ghc-options: -with-rtsopts "-T -K36K -M16M"
168 main-is: Streamly/Benchmark/Prelude/Serial/O_1_Space.hs
168 main-is: Streamly/Benchmark/Prelude/Serial/O_1_Space.hs
169+ other-modules: NestedOps, NestedUnfoldOps
169
170
170benchmark serial-O-n-heap
171benchmark serial-O-n-heap
171 import: bench-options
172 import: bench-options
@@ -184,20 +185,7 @@ benchmark serial-O-n-space
184 type: exitcode-stdio-1.0
185 type: exitcode-stdio-1.0
185 ghc-options: -with-rtsopts "-T -K16M -M64M"
186 ghc-options: -with-rtsopts "-T -K16M -M64M"
186 main-is: Streamly/Benchmark/Prelude/Serial/O_n_Space.hs
187 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
188+ other-modules: NestedOps, NestedUnfoldOps
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
201
189
202benchmark base
190benchmark base
203 import: bench-options
191 import: bench-options