Split "base" benchmark into per module benchmarks

Also, use module name prefix on the benchmarks.
This commit is contained in:
Harendra Kumar 2020-06-02 19:36:18 +05:30
parent ae7a0250cd
commit 1c57096c3c
7 changed files with 114 additions and 109 deletions

View File

@ -1,12 +1,17 @@
#!/bin/bash
SERIAL_O_1="linear base"
SERIAL_O_n="serial-o-n-heap serial-o-n-stack serial-o-n-space \
base-o-n-heap base-o-n-stack base-o-n-space"
SERIAL_O_1="linear"
SERIAL_O_n="serial-o-n-heap serial-o-n-stack serial-o-n-space"
FOLD_BENCHMARKS="fold-o-1-space fold-o-n-heap"
UNFOLD_BENCHMARKS="unfold-o-1-space unfold-o-n-space"
SERIAL_BENCHMARKS="$SERIAL_O_1 $SERIAL_O_n $FOLD_BENCHMARKS"
SERIAL_BENCHMARKS="\
Data.Stream.StreamD \
Data.Stream.StreamK \
Data.Stream.StreamDK \
$SERIAL_O_1 \
$SERIAL_O_n \
$FOLD_BENCHMARKS"
# parallel benchmark-suite is separated because we run it with a higher
# heap size limit.
CONCURRENT_BENCHMARKS="linear-async linear-rate nested-concurrent parallel concurrent adaptive"
@ -34,10 +39,10 @@ bench_rts_opts () {
"serial-o-n-stack") echo -n "-T -K1M -M16M" ;;
"serial-o-n-heap") echo -n "-T -K36K -M128M" ;;
"serial-o-n-space") echo -n "-T -K16M -M64M" ;;
"base") echo -n "-T -K36K -M16M" ;;
"base-o-n-stack") echo -n "-T -K1M -M16M" ;;
"base-o-n-heap") echo -n "-T -K36K -M64M" ;;
"base-o-n-space") echo -n "-T -K32M -M32M" ;;
*/o-1-sp*) echo -n "-T -K36K -M16M" ;;
*/o-n-h*) echo -n "-T -K36K -M32M" ;;
*/o-n-st*) echo -n "-T -K1M -M16M" ;;
*/o-n-sp*) echo -n "-T -K1M -M32M" ;;
*) echo -n "" ;;
esac
@ -54,10 +59,6 @@ bench_exec () {
"serial-o-n-stack") echo -n "serial" ;;
"serial-o-n-heap") echo -n "serial" ;;
"serial-o-n-space") echo -n "serial" ;;
"base") echo -n "base" ;;
"base-o-n-stack") echo -n "base" ;;
"base-o-n-heap") echo -n "base" ;;
"base-o-n-space") echo -n "base" ;;
*) echo -n "$1" ;;
esac
}
@ -73,10 +74,6 @@ bench_gauge_opts () {
"serial-o-n-stack") echo -n "-m prefix o-n-stack" ;;
"serial-o-n-heap") echo -n "-m prefix o-n-heap" ;;
"serial-o-n-space") echo -n "-m prefix o-n-space" ;;
"base") echo -n "-m prefix o-1-space" ;;
"base-o-n-stack") echo -n "-m prefix o-n-stack" ;;
"base-o-n-heap") echo -n "-m prefix o-n-heap" ;;
"base-o-n-space") echo -n "-m prefix o-n-space" ;;
*) echo -n "" ;;
esac
}
@ -222,6 +219,12 @@ bench_output_file() {
echo "charts/$bench_name/results.csv"
}
# $1: command
function run_verbose() {
echo "$*"
bash -c "$*"
}
# --min-duration 0 means exactly one iteration per sample. We use a million
# iterations in the benchmarking code explicitly and do not use the iterations
# done by the benchmarking tool.
@ -277,8 +280,8 @@ run_bench () {
SPEED_OPTIONS="--stream-size 10000000 $QUICK_OPTS --include-first-iter"
fi
$bench_prog $SPEED_OPTIONS \
+RTS $(bench_rts_opts $bench_name) -RTS \
run_verbose $bench_prog $SPEED_OPTIONS \
+RTS $(bench_rts_opts $GAUGE_ARGS) -RTS \
--csvraw=$output_file \
-v 2 \
--measure-with $bench_prog $GAUGE_ARGS \

View File

@ -1,27 +0,0 @@
-- |
-- Module : Main
-- Copyright : (c) 2018 Harendra Kumar
--
-- License : BSD3
-- Maintainer : streamly@composewell.com
import qualified Streamly.Benchmark.Data.Stream.StreamK as K
import qualified Streamly.Benchmark.Data.Stream.StreamD as D
import qualified Streamly.Benchmark.Data.Stream.StreamDK as DK
import Gauge
main :: IO ()
main =
defaultMain $
[ bgroup "o-n-stack" o_n_stack
, bgroup "o-1-space" o_1_space
, bgroup "o-n-heap" o_n_heap
, bgroup "o-n-space" o_n_space
]
where
o_1_space =
concat [D.o_1_space, K.o_1_space_list, K.o_1_space, DK.o_1_space]
o_n_heap = K.o_n_heap
o_n_stack = concat [D.o_n_stack, K.o_n_stack]
o_n_space = concat [D.o_n_space, K.o_n_space]

View File

@ -8,30 +8,19 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Streamly.Benchmark.Data.Stream.StreamD
(
o_1_space
, o_n_stack
, o_n_space
)
where
module Main (main) where
import Control.Monad (when)
import Data.Maybe (isJust)
import Prelude
(Monad, Int, (+), ($), (.), return, (>), even, (<=), div,
subtract, undefined, Maybe(..), not, (>>=),
maxBound, fmap, odd, (==), flip, (<$>), (<*>), round, (/), (**), (<))
import Gauge (bench, nfIO, bgroup, Benchmark, defaultMain)
import System.Random (randomRIO)
import Prelude hiding (tail, mapM_, foldl, last, map, mapM, concatMap, zip)
import qualified Prelude as P
import qualified Streamly.Internal.Data.Stream.StreamD as S
import qualified Streamly.Internal.Data.Unfold as UF
import Streamly.Benchmark.Common (benchFold)
import Gauge (bench, nfIO, bgroup, Benchmark)
import Streamly.Benchmark.Common
-- We try to keep the total number of iterations same irrespective of nesting
-- of the loops so that the overhead is easy to compare.
@ -368,9 +357,12 @@ filterAllInNested str = runStream $ do
-- Benchmarks
-------------------------------------------------------------------------------
moduleName :: String
moduleName = "Data.Stream.StreamD"
o_1_space :: [Benchmark]
o_1_space =
[ bgroup "streamD"
[ bgroup (o_1_space_prefix moduleName)
[ bgroup "generation"
[ benchFold "unfoldr" toNull sourceUnfoldr
, benchFold "unfoldrM" toNull sourceUnfoldrM
@ -494,7 +486,7 @@ benchD name f = bench name $ nfIO $ randomRIO (1,1) >>= toNull . f
o_n_stack :: [Benchmark]
o_n_stack =
[ bgroup "streamD"
[ bgroup (o_n_stack_prefix moduleName)
[ bgroup "elimination"
[ benchFold "tail" tail sourceUnfoldrM
, benchFold "nullTail" nullTail sourceUnfoldrM
@ -527,7 +519,7 @@ o_n_stack =
o_n_space :: [Benchmark]
o_n_space =
[ bgroup "streamD"
[ bgroup (o_n_space_prefix moduleName)
[ bgroup "elimination"
[ benchFold "toList" toList sourceUnfoldrM
]
@ -539,3 +531,6 @@ o_n_space =
]
]
]
main :: IO ()
main = defaultMain $ concat [o_1_space, o_n_stack, o_n_space]

View File

@ -8,16 +8,11 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Streamly.Benchmark.Data.Stream.StreamDK
(
o_1_space
)
where
module Main (main) where
-- import Control.Monad (when)
-- import Data.Maybe (isJust)
import Prelude
(Monad, Int, (+), return, Maybe(..), (>))
import Prelude hiding ()
-- import qualified Prelude as P
-- import qualified Data.List as List
@ -25,8 +20,8 @@ import qualified Streamly.Internal.Data.Stream.StreamDK as S
-- import qualified Streamly.Internal.Data.Stream.Prelude as SP
-- import qualified Streamly.Internal.Data.SVar as S
import Streamly.Benchmark.Common (benchFold)
import Gauge (bgroup, Benchmark)
import Streamly.Benchmark.Common
import Gauge (bgroup, Benchmark, defaultMain)
value :: Int
value = 100000
@ -437,9 +432,12 @@ filterAllInNestedList str = do
-- Benchmarks
-------------------------------------------------------------------------------
moduleName :: String
moduleName = "Data.Stream.StreamDK"
o_1_space :: [Benchmark]
o_1_space =
[ bgroup "streamDK"
[ bgroup (o_1_space_prefix moduleName)
[ bgroup "generation"
[ benchFold "unfoldr" toNull sourceUnfoldr
, benchFold "unfoldrM" toNull sourceUnfoldrM
@ -450,3 +448,6 @@ o_1_space =
]
]
]
main :: IO ()
main = defaultMain $ concat [o_1_space]

View File

@ -8,23 +8,14 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Streamly.Benchmark.Data.Stream.StreamK
(
o_1_space
, o_n_stack
, o_n_heap
, o_n_space
, o_1_space_list
)
where
module Main (main) where
import Control.Monad (when)
import Data.Maybe (isJust)
import Prelude
(Monad, Int, (+), ($), (.), return, even, (>), (<=), div,
subtract, undefined, Maybe(..), not, (>>=),
maxBound, flip, (<$>), (<*>), round, (/), (**), (<), foldr, fmap)
import System.Random (randomRIO)
import Prelude hiding
(tail, mapM_, foldl, last, map, mapM, concatMap, zip, init)
import qualified Prelude as P
import qualified Data.List as List
@ -32,8 +23,9 @@ import qualified Streamly.Internal.Data.Stream.StreamK as S
import qualified Streamly.Internal.Data.Stream.Prelude as SP
import qualified Streamly.Internal.Data.SVar as S
import Streamly.Benchmark.Common (benchFold)
import Gauge (bench, nfIO, bgroup, Benchmark)
import Gauge (bench, nfIO, bgroup, Benchmark, defaultMain)
import Streamly.Benchmark.Common
value, value2, value3, value16, maxValue :: Int
value = 100000
@ -416,9 +408,12 @@ filterAllInNestedList str = do
-- Benchmarks
-------------------------------------------------------------------------------
moduleName :: String
moduleName = "Data.Stream.StreamK"
o_1_space :: [Benchmark]
o_1_space =
[ bgroup "streamK"
[ bgroup (o_1_space_prefix moduleName)
[ bgroup "generation"
[ benchFold "unfoldr" toNull sourceUnfoldr
, benchFold "unfoldrM" toNull sourceUnfoldrM
@ -538,7 +533,7 @@ o_1_space =
o_n_heap :: [Benchmark]
o_n_heap =
[ bgroup "streamK"
[ bgroup (o_n_heap_prefix moduleName)
[ bgroup "transformation"
[ benchFold "foldlS" (foldlS 1) sourceUnfoldrM
]
@ -551,7 +546,7 @@ benchK name f = bench name $ nfIO $ randomRIO (1,1) >>= toNull . f
o_n_stack :: [Benchmark]
o_n_stack =
[ bgroup "streamK"
[ bgroup (o_n_stack_prefix moduleName)
[ bgroup "elimination"
[ benchFold "tail" tail sourceUnfoldrM
, benchFold "nullTail" nullTail sourceUnfoldrM
@ -581,7 +576,7 @@ o_n_stack =
o_n_space :: [Benchmark]
o_n_space =
[ bgroup "streamK"
[ bgroup (o_n_space_prefix moduleName)
[ bgroup "elimination"
[ benchFold "toList" toList sourceUnfoldrM
]
@ -607,3 +602,12 @@ o_1_space_list =
]
]
]
main :: IO ()
main = defaultMain $ concat
[ o_1_space
, [bgroup (o_1_space_prefix moduleName) o_1_space_list]
, o_n_stack
, o_n_heap
, o_n_space
]

View File

@ -11,7 +11,12 @@
-- Maintainer : streamly@composewell.com
module Streamly.Benchmark.Common
( parseCLIOpts
( o_1_space_prefix
, o_n_space_prefix
, o_n_heap_prefix
, o_n_stack_prefix
, parseCLIOpts
, benchIOSink1
, benchPure
@ -47,6 +52,22 @@ import qualified Streamly.Prelude as S
import Streamly
import Gauge
-------------------------------------------------------------------------------
-- Benchmark Prefixes
-------------------------------------------------------------------------------
o_1_space_prefix :: String -> String
o_1_space_prefix name = name ++ "/o-1-space"
o_n_space_prefix :: String -> String
o_n_space_prefix name = name ++ "/o-n-space"
o_n_heap_prefix :: String -> String
o_n_heap_prefix name = name ++ "/o-n-heap"
o_n_stack_prefix :: String -> String
o_n_stack_prefix name = name ++ "/o-n-stack"
-------------------------------------------------------------------------------
-- Benchmarking utilities
-------------------------------------------------------------------------------

View File

@ -253,29 +253,37 @@ benchmark parser
-- Raw Streams
-------------------------------------------------------------------------------
library lib-base
import: lib-options, bench-depends
hs-source-dirs: .
exposed-modules:
Streamly.Benchmark.Data.Stream.StreamD
, Streamly.Benchmark.Data.Stream.StreamK
, Streamly.Benchmark.Data.Stream.StreamDK
if impl(ghcjs)
buildable: False
else
build-depends: streamly-benchmarks
buildable: True
benchmark base
benchmark Data.Stream.StreamD
import: bench-options
type: exitcode-stdio-1.0
ghc-options: -rtsopts
hs-source-dirs: Streamly/Benchmark/Data/Stream
main-is: BaseStreams.hs
main-is: StreamD.hs
if impl(ghcjs)
buildable: False
else
buildable: True
benchmark Data.Stream.StreamK
import: bench-options
type: exitcode-stdio-1.0
ghc-options: -rtsopts
hs-source-dirs: Streamly/Benchmark/Data/Stream
main-is: StreamK.hs
if impl(ghcjs)
buildable: False
else
buildable: True
benchmark Data.Stream.StreamDK
import: bench-options
type: exitcode-stdio-1.0
ghc-options: -rtsopts
hs-source-dirs: Streamly/Benchmark/Data/Stream
main-is: StreamDK.hs
if impl(ghcjs)
buildable: False
else
build-depends: lib-base
buildable: True
executable nano-bench