on master help sign in
Split "base" benchmark into per module benchmarks
1c57096Harendra Kumar
bench.sh+21−18
@@ -1,12 +1,17 @@
1#!/bin/bash
1#!/bin/bash
2
2
3−SERIAL_O_1="linear base"
3+SERIAL_O_1="linear"
4−SERIAL_O_n="serial-o-n-heap serial-o-n-stack serial-o-n-space \
4+SERIAL_O_n="serial-o-n-heap serial-o-n-stack serial-o-n-space"
5− base-o-n-heap base-o-n-stack base-o-n-space"
6FOLD_BENCHMARKS="fold-o-1-space fold-o-n-heap"
5FOLD_BENCHMARKS="fold-o-1-space fold-o-n-heap"
7UNFOLD_BENCHMARKS="unfold-o-1-space unfold-o-n-space"
6UNFOLD_BENCHMARKS="unfold-o-1-space unfold-o-n-space"
8
7
9−SERIAL_BENCHMARKS="$SERIAL_O_1 $SERIAL_O_n $FOLD_BENCHMARKS"
8+SERIAL_BENCHMARKS="\
9+ Data.Stream.StreamD \
10+ Data.Stream.StreamK \
11+ Data.Stream.StreamDK \
12+ $SERIAL_O_1 \
13+ $SERIAL_O_n \
14+ $FOLD_BENCHMARKS"
10# parallel benchmark-suite is separated because we run it with a higher
15# parallel benchmark-suite is separated because we run it with a higher
11# heap size limit.
16# heap size limit.
12CONCURRENT_BENCHMARKS="linear-async linear-rate nested-concurrent parallel concurrent adaptive"
17CONCURRENT_BENCHMARKS="linear-async linear-rate nested-concurrent parallel concurrent adaptive"
@@ -34,10 +39,10 @@ bench_rts_opts () {
34 "serial-o-n-stack") echo -n "-T -K1M -M16M" ;;
39 "serial-o-n-stack") echo -n "-T -K1M -M16M" ;;
35 "serial-o-n-heap") echo -n "-T -K36K -M128M" ;;
40 "serial-o-n-heap") echo -n "-T -K36K -M128M" ;;
36 "serial-o-n-space") echo -n "-T -K16M -M64M" ;;
41 "serial-o-n-space") echo -n "-T -K16M -M64M" ;;
37− "base") echo -n "-T -K36K -M16M" ;;
42+ */o-1-sp*) echo -n "-T -K36K -M16M" ;;
38− "base-o-n-stack") echo -n "-T -K1M -M16M" ;;
43+ */o-n-h*) echo -n "-T -K36K -M32M" ;;
39− "base-o-n-heap") echo -n "-T -K36K -M64M" ;;
44+ */o-n-st*) echo -n "-T -K1M -M16M" ;;
40− "base-o-n-space") echo -n "-T -K32M -M32M" ;;
45+ */o-n-sp*) echo -n "-T -K1M -M32M" ;;
41
46
42 *) echo -n "" ;;
47 *) echo -n "" ;;
43 esac
48 esac
@@ -54,10 +59,6 @@ bench_exec () {
54 "serial-o-n-stack") echo -n "serial" ;;
59 "serial-o-n-stack") echo -n "serial" ;;
55 "serial-o-n-heap") echo -n "serial" ;;
60 "serial-o-n-heap") echo -n "serial" ;;
56 "serial-o-n-space") echo -n "serial" ;;
61 "serial-o-n-space") echo -n "serial" ;;
57− "base") echo -n "base" ;;
58− "base-o-n-stack") echo -n "base" ;;
59− "base-o-n-heap") echo -n "base" ;;
60− "base-o-n-space") echo -n "base" ;;
61 *) echo -n "$1" ;;
62 *) echo -n "$1" ;;
62 esac
63 esac
63}
64}
@@ -73,10 +74,6 @@ bench_gauge_opts () {
73 "serial-o-n-stack") echo -n "-m prefix o-n-stack" ;;
74 "serial-o-n-stack") echo -n "-m prefix o-n-stack" ;;
74 "serial-o-n-heap") echo -n "-m prefix o-n-heap" ;;
75 "serial-o-n-heap") echo -n "-m prefix o-n-heap" ;;
75 "serial-o-n-space") echo -n "-m prefix o-n-space" ;;
76 "serial-o-n-space") echo -n "-m prefix o-n-space" ;;
76− "base") echo -n "-m prefix o-1-space" ;;
77− "base-o-n-stack") echo -n "-m prefix o-n-stack" ;;
78− "base-o-n-heap") echo -n "-m prefix o-n-heap" ;;
79− "base-o-n-space") echo -n "-m prefix o-n-space" ;;
80 *) echo -n "" ;;
77 *) echo -n "" ;;
81 esac
78 esac
82}
79}
@@ -222,6 +219,12 @@ bench_output_file() {
222 echo "charts/$bench_name/results.csv"
219 echo "charts/$bench_name/results.csv"
223}
220}
224
221
222+# $1: command
223+function run_verbose() {
224+ echo "$*"
225+ bash -c "$*"
226+}
227+
225# --min-duration 0 means exactly one iteration per sample. We use a million
228# --min-duration 0 means exactly one iteration per sample. We use a million
226# iterations in the benchmarking code explicitly and do not use the iterations
229# iterations in the benchmarking code explicitly and do not use the iterations
227# done by the benchmarking tool.
230# done by the benchmarking tool.
@@ -277,8 +280,8 @@ run_bench () {
277 SPEED_OPTIONS="--stream-size 10000000 $QUICK_OPTS --include-first-iter"
280 SPEED_OPTIONS="--stream-size 10000000 $QUICK_OPTS --include-first-iter"
278 fi
281 fi
279
282
280− $bench_prog $SPEED_OPTIONS \
283+ run_verbose $bench_prog $SPEED_OPTIONS \
281− +RTS $(bench_rts_opts $bench_name) -RTS \
284+ +RTS $(bench_rts_opts $GAUGE_ARGS) -RTS \
282 --csvraw=$output_file \
285 --csvraw=$output_file \
283 -v 2 \
286 -v 2 \
284 --measure-with $bench_prog $GAUGE_ARGS \
287 --measure-with $bench_prog $GAUGE_ARGS \
benchmark/Streamly/Benchmark/Data/Stream/BaseStreams.hsdeleted−27
@@ -1,27 +0,0 @@
1−-- |
2−-- Module : Main
3−-- Copyright : (c) 2018 Harendra Kumar
4−--
5−-- License : BSD3
6−-- Maintainer : streamly@composewell.com
7−
8−import qualified Streamly.Benchmark.Data.Stream.StreamK as K
9−import qualified Streamly.Benchmark.Data.Stream.StreamD as D
10−import qualified Streamly.Benchmark.Data.Stream.StreamDK as DK
11−
12−import Gauge
13−
14−main :: IO ()
15−main =
16− defaultMain $
17− [ bgroup "o-n-stack" o_n_stack
18− , bgroup "o-1-space" o_1_space
19− , bgroup "o-n-heap" o_n_heap
20− , bgroup "o-n-space" o_n_space
21− ]
22− where
23− o_1_space =
24− concat [D.o_1_space, K.o_1_space_list, K.o_1_space, DK.o_1_space]
25− o_n_heap = K.o_n_heap
26− o_n_stack = concat [D.o_n_stack, K.o_n_stack]
27− o_n_space = concat [D.o_n_space, K.o_n_space]
benchmark/Streamly/Benchmark/Data/Stream/StreamD.hs+13−18
@@ -8,30 +8,19 @@
8{-# LANGUAGE FlexibleContexts #-}
8{-# LANGUAGE FlexibleContexts #-}
9{-# LANGUAGE ScopedTypeVariables #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10
10
11−module Streamly.Benchmark.Data.Stream.StreamD
12− (
13− o_1_space
14− , o_n_stack
15− , o_n_space
16− )
17−where
11+module Main (main) where
18
12
19import Control.Monad (when)
13import Control.Monad (when)
20import Data.Maybe (isJust)
14import Data.Maybe (isJust)
21−import Prelude
15+import Gauge (bench, nfIO, bgroup, Benchmark, defaultMain)
22− (Monad, Int, (+), ($), (.), return, (>), even, (<=), div,
23− subtract, undefined, Maybe(..), not, (>>=),
24− maxBound, fmap, odd, (==), flip, (<$>), (<*>), round, (/), (**), (<))
25import System.Random (randomRIO)
16import System.Random (randomRIO)
17+import Prelude hiding (tail, mapM_, foldl, last, map, mapM, concatMap, zip)
26
18
27import qualified Prelude as P
19import qualified Prelude as P
28−
29import qualified Streamly.Internal.Data.Stream.StreamD as S
20import qualified Streamly.Internal.Data.Stream.StreamD as S
30import qualified Streamly.Internal.Data.Unfold as UF
21import qualified Streamly.Internal.Data.Unfold as UF
31
22
32−import Streamly.Benchmark.Common (benchFold)
23+import Streamly.Benchmark.Common
33−import Gauge (bench, nfIO, bgroup, Benchmark)
34−
35
24
36-- We try to keep the total number of iterations same irrespective of nesting
25-- We try to keep the total number of iterations same irrespective of nesting
37-- of the loops so that the overhead is easy to compare.
26-- of the loops so that the overhead is easy to compare.
@@ -368,9 +357,12 @@ filterAllInNested str = runStream $ do
368-- Benchmarks
357-- Benchmarks
369-------------------------------------------------------------------------------
358-------------------------------------------------------------------------------
370
359
360+moduleName :: String
361+moduleName = "Data.Stream.StreamD"
362+
371o_1_space :: [Benchmark]
363o_1_space :: [Benchmark]
372o_1_space =
364o_1_space =
373− [ bgroup "streamD"
365+ [ bgroup (o_1_space_prefix moduleName)
374 [ bgroup "generation"
366 [ bgroup "generation"
375 [ benchFold "unfoldr" toNull sourceUnfoldr
367 [ benchFold "unfoldr" toNull sourceUnfoldr
376 , benchFold "unfoldrM" toNull sourceUnfoldrM
368 , benchFold "unfoldrM" toNull sourceUnfoldrM
@@ -494,7 +486,7 @@ benchD name f = bench name $ nfIO $ randomRIO (1,1) >>= toNull . f
494
486
495o_n_stack :: [Benchmark]
487o_n_stack :: [Benchmark]
496o_n_stack =
488o_n_stack =
497− [ bgroup "streamD"
489+ [ bgroup (o_n_stack_prefix moduleName)
498 [ bgroup "elimination"
490 [ bgroup "elimination"
499 [ benchFold "tail" tail sourceUnfoldrM
491 [ benchFold "tail" tail sourceUnfoldrM
500 , benchFold "nullTail" nullTail sourceUnfoldrM
492 , benchFold "nullTail" nullTail sourceUnfoldrM
@@ -527,7 +519,7 @@ o_n_stack =
527
519
528o_n_space :: [Benchmark]
520o_n_space :: [Benchmark]
529o_n_space =
521o_n_space =
530− [ bgroup "streamD"
522+ [ bgroup (o_n_space_prefix moduleName)
531 [ bgroup "elimination"
523 [ bgroup "elimination"
532 [ benchFold "toList" toList sourceUnfoldrM
524 [ benchFold "toList" toList sourceUnfoldrM
533 ]
525 ]
@@ -539,3 +531,6 @@ o_n_space =
539 ]
531 ]
540 ]
532 ]
541 ]
533 ]
534+
535+main :: IO ()
536+main = defaultMain $ concat [o_1_space, o_n_stack, o_n_space]
benchmark/Streamly/Benchmark/Data/Stream/StreamDK.hs+11−10
@@ -8,16 +8,11 @@
8{-# LANGUAGE FlexibleContexts #-}
8{-# LANGUAGE FlexibleContexts #-}
9{-# LANGUAGE ScopedTypeVariables #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10
10
11−module Streamly.Benchmark.Data.Stream.StreamDK
12− (
13− o_1_space
14− )
15−where
11+module Main (main) where
16
12
17-- import Control.Monad (when)
13-- import Control.Monad (when)
18-- import Data.Maybe (isJust)
14-- import Data.Maybe (isJust)
19−import Prelude
15+import Prelude hiding ()
20− (Monad, Int, (+), return, Maybe(..), (>))
21-- import qualified Prelude as P
16-- import qualified Prelude as P
22-- import qualified Data.List as List
17-- import qualified Data.List as List
23
18
@@ -25,8 +20,8 @@ import qualified Streamly.Internal.Data.Stream.StreamDK as S
25-- import qualified Streamly.Internal.Data.Stream.Prelude as SP
20-- import qualified Streamly.Internal.Data.Stream.Prelude as SP
26-- import qualified Streamly.Internal.Data.SVar as S
21-- import qualified Streamly.Internal.Data.SVar as S
27
22
28−import Streamly.Benchmark.Common (benchFold)
23+import Streamly.Benchmark.Common
29−import Gauge (bgroup, Benchmark)
24+import Gauge (bgroup, Benchmark, defaultMain)
30
25
31value :: Int
26value :: Int
32value = 100000
27value = 100000
@@ -437,9 +432,12 @@ filterAllInNestedList str = do
437-- Benchmarks
432-- Benchmarks
438-------------------------------------------------------------------------------
433-------------------------------------------------------------------------------
439
434
435+moduleName :: String
436+moduleName = "Data.Stream.StreamDK"
437+
440o_1_space :: [Benchmark]
438o_1_space :: [Benchmark]
441o_1_space =
439o_1_space =
442− [ bgroup "streamDK"
440+ [ bgroup (o_1_space_prefix moduleName)
443 [ bgroup "generation"
441 [ bgroup "generation"
444 [ benchFold "unfoldr" toNull sourceUnfoldr
442 [ benchFold "unfoldr" toNull sourceUnfoldr
445 , benchFold "unfoldrM" toNull sourceUnfoldrM
443 , benchFold "unfoldrM" toNull sourceUnfoldrM
@@ -450,3 +448,6 @@ o_1_space =
450 ]
448 ]
451 ]
449 ]
452 ]
450 ]
451+
452+main :: IO ()
453+main = defaultMain $ concat [o_1_space]
benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs+23−19
@@ -8,23 +8,14 @@
8{-# LANGUAGE FlexibleContexts #-}
8{-# LANGUAGE FlexibleContexts #-}
9{-# LANGUAGE ScopedTypeVariables #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10
10
11−module Streamly.Benchmark.Data.Stream.StreamK
12− (
13− o_1_space
14− , o_n_stack
15− , o_n_heap
16− , o_n_space
17− , o_1_space_list
18− )
19−where
11+module Main (main) where
20
12
21import Control.Monad (when)
13import Control.Monad (when)
22import Data.Maybe (isJust)
14import Data.Maybe (isJust)
23−import Prelude
24− (Monad, Int, (+), ($), (.), return, even, (>), (<=), div,
25− subtract, undefined, Maybe(..), not, (>>=),
26− maxBound, flip, (<$>), (<*>), round, (/), (**), (<), foldr, fmap)
27import System.Random (randomRIO)
15import System.Random (randomRIO)
16+import Prelude hiding
17+ (tail, mapM_, foldl, last, map, mapM, concatMap, zip, init)
18+
28import qualified Prelude as P
19import qualified Prelude as P
29import qualified Data.List as List
20import qualified Data.List as List
30
21
@@ -32,8 +23,9 @@ import qualified Streamly.Internal.Data.Stream.StreamK as S
32import qualified Streamly.Internal.Data.Stream.Prelude as SP
23import qualified Streamly.Internal.Data.Stream.Prelude as SP
33import qualified Streamly.Internal.Data.SVar as S
24import qualified Streamly.Internal.Data.SVar as S
34
25
35−import Streamly.Benchmark.Common (benchFold)
36−import Gauge (bench, nfIO, bgroup, Benchmark)
26+import Gauge (bench, nfIO, bgroup, Benchmark, defaultMain)
27+
28+import Streamly.Benchmark.Common
37
29
38value, value2, value3, value16, maxValue :: Int
30value, value2, value3, value16, maxValue :: Int
39value = 100000
31value = 100000
@@ -416,9 +408,12 @@ filterAllInNestedList str = do
416-- Benchmarks
408-- Benchmarks
417-------------------------------------------------------------------------------
409-------------------------------------------------------------------------------
418
410
411+moduleName :: String
412+moduleName = "Data.Stream.StreamK"
413+
419o_1_space :: [Benchmark]
414o_1_space :: [Benchmark]
420o_1_space =
415o_1_space =
421− [ bgroup "streamK"
416+ [ bgroup (o_1_space_prefix moduleName)
422 [ bgroup "generation"
417 [ bgroup "generation"
423 [ benchFold "unfoldr" toNull sourceUnfoldr
418 [ benchFold "unfoldr" toNull sourceUnfoldr
424 , benchFold "unfoldrM" toNull sourceUnfoldrM
419 , benchFold "unfoldrM" toNull sourceUnfoldrM
@@ -538,7 +533,7 @@ o_1_space =
538
533
539o_n_heap :: [Benchmark]
534o_n_heap :: [Benchmark]
540o_n_heap =
535o_n_heap =
541− [ bgroup "streamK"
536+ [ bgroup (o_n_heap_prefix moduleName)
542 [ bgroup "transformation"
537 [ bgroup "transformation"
543 [ benchFold "foldlS" (foldlS 1) sourceUnfoldrM
538 [ benchFold "foldlS" (foldlS 1) sourceUnfoldrM
544 ]
539 ]
@@ -551,7 +546,7 @@ benchK name f = bench name $ nfIO $ randomRIO (1,1) >>= toNull . f
551
546
552o_n_stack :: [Benchmark]
547o_n_stack :: [Benchmark]
553o_n_stack =
548o_n_stack =
554− [ bgroup "streamK"
549+ [ bgroup (o_n_stack_prefix moduleName)
555 [ bgroup "elimination"
550 [ bgroup "elimination"
556 [ benchFold "tail" tail sourceUnfoldrM
551 [ benchFold "tail" tail sourceUnfoldrM
557 , benchFold "nullTail" nullTail sourceUnfoldrM
552 , benchFold "nullTail" nullTail sourceUnfoldrM
@@ -581,7 +576,7 @@ o_n_stack =
581
576
582o_n_space :: [Benchmark]
577o_n_space :: [Benchmark]
583o_n_space =
578o_n_space =
584− [ bgroup "streamK"
579+ [ bgroup (o_n_space_prefix moduleName)
585 [ bgroup "elimination"
580 [ bgroup "elimination"
586 [ benchFold "toList" toList sourceUnfoldrM
581 [ benchFold "toList" toList sourceUnfoldrM
587 ]
582 ]
@@ -607,3 +602,12 @@ o_1_space_list =
607 ]
602 ]
608 ]
603 ]
609 ]
604 ]
605+
606+main :: IO ()
607+main = defaultMain $ concat
608+ [ o_1_space
609+ , [bgroup (o_1_space_prefix moduleName) o_1_space_list]
610+ , o_n_stack
611+ , o_n_heap
612+ , o_n_space
613+ ]
benchmark/lib/Streamly/Benchmark/Common.hs+22−1
@@ -11,7 +11,12 @@
11-- Maintainer : streamly@composewell.com
11-- Maintainer : streamly@composewell.com
12
12
13module Streamly.Benchmark.Common
13module Streamly.Benchmark.Common
14+ ( o_1_space_prefix
15+ , o_n_space_prefix
16+ , o_n_heap_prefix
17+ , o_n_stack_prefix
18+
14− ( parseCLIOpts
19+ , parseCLIOpts
15
20
16 , benchIOSink1
21 , benchIOSink1
17 , benchPure
22 , benchPure
@@ -47,6 +52,22 @@ import qualified Streamly.Prelude as S
47import Streamly
52import Streamly
48import Gauge
53import Gauge
49
54
55+-------------------------------------------------------------------------------
56+-- Benchmark Prefixes
57+-------------------------------------------------------------------------------
58+
59+o_1_space_prefix :: String -> String
60+o_1_space_prefix name = name ++ "/o-1-space"
61+
62+o_n_space_prefix :: String -> String
63+o_n_space_prefix name = name ++ "/o-n-space"
64+
65+o_n_heap_prefix :: String -> String
66+o_n_heap_prefix name = name ++ "/o-n-heap"
67+
68+o_n_stack_prefix :: String -> String
69+o_n_stack_prefix name = name ++ "/o-n-stack"
70+
50-------------------------------------------------------------------------------
71-------------------------------------------------------------------------------
51-- Benchmarking utilities
72-- Benchmarking utilities
52-------------------------------------------------------------------------------
73-------------------------------------------------------------------------------
benchmark/streamly-benchmarks.cabal+23−15
@@ -253,29 +253,37 @@ benchmark parser
253-- Raw Streams
253-- Raw Streams
254-------------------------------------------------------------------------------
254-------------------------------------------------------------------------------
255
255
256−library lib-base
256+benchmark Data.Stream.StreamD
257− import: lib-options, bench-depends
257+ import: bench-options
258+ type: exitcode-stdio-1.0
259+ ghc-options: -rtsopts
258− hs-source-dirs: .
260+ hs-source-dirs: Streamly/Benchmark/Data/Stream
259− exposed-modules:
261+ main-is: StreamD.hs
260− Streamly.Benchmark.Data.Stream.StreamD
262+ if impl(ghcjs)
261− , Streamly.Benchmark.Data.Stream.StreamK
263+ buildable: False
264+ else
265+ buildable: True
266+
267+benchmark Data.Stream.StreamK
268+ import: bench-options
269+ type: exitcode-stdio-1.0
270+ ghc-options: -rtsopts
262− , Streamly.Benchmark.Data.Stream.StreamDK
271+ hs-source-dirs: Streamly/Benchmark/Data/Stream
272+ main-is: StreamK.hs
263− if impl(ghcjs)
273+ if impl(ghcjs)
264− buildable: False
274+ buildable: False
265− else
275+ else
266− build-depends: streamly-benchmarks
267− buildable: True
276+ buildable: True
268
277
269−benchmark base
278+benchmark Data.Stream.StreamDK
270 import: bench-options
279 import: bench-options
271 type: exitcode-stdio-1.0
280 type: exitcode-stdio-1.0
272 ghc-options: -rtsopts
281 ghc-options: -rtsopts
273 hs-source-dirs: Streamly/Benchmark/Data/Stream
282 hs-source-dirs: Streamly/Benchmark/Data/Stream
274− main-is: BaseStreams.hs
283+ main-is: StreamDK.hs
275 if impl(ghcjs)
284 if impl(ghcjs)
276 buildable: False
285 buildable: False
277 else
286 else
278− build-depends: lib-base
279 buildable: True
287 buildable: True
280
288
281executable nano-bench
289executable nano-bench