on master help sign in
Move unfold benchmarks out of prelude. Make a seperate exec.
commit633e88f8c59be2336e4f18126778c254ccb0f683 authoradithyaov <adi.obilisetty@gmail.com> dateWed 8 Apr 2020, 17:41 (7 years ago) parent24e481c
7 files changed+111−35
bench.sh+7 benchmark/Chart.hs+14 benchmark/Streamly/Benchmark/Data/Unfold.hs+77 benchmark/Streamly/Benchmark/Prelude/Serial/O_1_Space.hs−1 benchmark/Streamly/Benchmark/Prelude/Serial/O_n_Space.hs−1 benchmark/lib/Streamly/Benchmark/Prelude.hs−32 benchmark/streamly-benchmarks.cabal+13−1
bench.sh+7
@@ -4,6 +4,7 @@ SERIAL_O_1="linear base"
44SERIAL_O_n="serial-o-n-heap serial-o-n-stack serial-o-n-space \
55 base-o-n-heap base-o-n-stack base-o-n-space"
66FOLD_BENCHMARKS="fold-o-1-space fold-o-n-heap"
7+UNFOLD_BENCHMARKS="unfold-o-1-space unfold-o-n-space"
78
89SERIAL_BENCHMARKS="$SERIAL_O_1 $SERIAL_O_n $FOLD_BENCHMARKS"
910# parallel benchmark-suite is separated because we run it with a higher
@@ -27,6 +28,8 @@ bench_rts_opts () {
2728 case "$1" in
2829 "fold-o-1-space") echo -n "-T -K36K -M16M" ;;
2930 "fold-o-n-heap") echo -n "-T -K36K -M128M" ;;
31+ "unfold-o-1-space") echo -n "-T -K36K -M16M" ;;
32+ "unfold-o-n-space") echo -n "-T -K32M -M64M" ;;
3033 *) echo -n "" ;;
3134 esac
3235}
@@ -36,6 +39,8 @@ bench_exec () {
3639 case "$1" in
3740 "fold-o-1-space") echo -n "fold" ;;
3841 "fold-o-n-heap") echo -n "fold" ;;
42+ "unfold-o-1-space") echo -n "unfold" ;;
43+ "unfold-o-n-space") echo -n "unfold" ;;
3944 *) echo -n "$1" ;;
4045 esac
4146}
@@ -45,6 +50,8 @@ bench_gauge_opts () {
4550 case "$1" in
4651 "fold-o-1-space") echo -n "-m prefix o-1-space" ;;
4752 "fold-o-n-heap") echo -n "-m prefix o-n-heap" ;;
53+ "unfold-o-1-space") echo -n "-m prefix o-1-space" ;;
54+ "unfold-o-n-space") echo -n "-m prefix o-n-space" ;;
4855 *) echo -n "" ;;
4956 esac
5057}
benchmark/Chart.hs+14
@@ -40,6 +40,8 @@ data BenchType
4040 | Adaptive
4141 | FoldO1Space
4242 | FoldOnHeap
43+ | UnfoldO1Space
44+ | UnfoldOnSpace
4345 deriving Show
4446
4547data Options = Options
@@ -90,6 +92,8 @@ parseBench = do
9092 Just "adaptive" -> setBenchType Adaptive
9193 Just "fold-o-1-space" -> setBenchType FoldO1Space
9294 Just "fold-o-n-heap" -> setBenchType FoldOnHeap
95+ Just "unfold-o-1-space" -> setBenchType UnfoldO1Space
96+ Just "unfold-o-n-space" -> setBenchType UnfoldOnSpace
9397 Just str -> do
9498 liftIO $ putStrLn $ "unrecognized benchmark type " <> str
9599 mzero
@@ -423,3 +427,13 @@ main = do
423427 (makeGraphs "fold-o-n-heap")
424428 "charts/fold-o-n-heap/results.csv"
425429 "charts/fold-o-n-heap"
430+ UnfoldO1Space -> benchShow opts cfg
431+ { title = Just "Unfold O(1) Space" }
432+ (makeGraphs "unfold-o-1-space")
433+ "charts/unfold-o-1-space/results.csv"
434+ "charts/unfold-o-1-space"
435+ UnfoldOnSpace -> benchShow opts cfg
436+ { title = Just "Unfold O(n) Space" }
437+ (makeGraphs "unfold-o-n-space")
438+ "charts/unfold-o-n-space/results.csv"
439+ "charts/unfold-o-n-space"
benchmark/Streamly/Benchmark/Data/Unfold.hsnew file+77
@@ -0,0 +1,77 @@
1+-- |
2+-- Module : Streamly.Benchmark.Data.Fold
3+-- Copyright : (c) 2018 Composewell
4+--
5+-- License : MIT
6+-- Maintainer : streamly@composewell.com
7+
8+{-# LANGUAGE FlexibleContexts #-}
9+
10+module Main (main) where
11+
12+import Control.DeepSeq (NFData(..))
13+
14+import System.Random (randomRIO)
15+
16+import Gauge
17+
18+import Prelude hiding (concat)
19+
20+import Streamly.Benchmark.Common
21+import Streamly.Benchmark.Data.NestedUnfoldOps
22+
23+{-# INLINE benchIO #-}
24+benchIO :: (NFData b) => String -> (Int -> IO b) -> Benchmark
25+benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
26+
27+-------------------------------------------------------------------------------
28+-- Stream folds
29+-------------------------------------------------------------------------------
30+
31+o_1_space_serial_outerProductUnfolds :: Int -> [Benchmark]
32+o_1_space_serial_outerProductUnfolds value =
33+ [ bgroup
34+ "serially"
35+ [ bgroup
36+ "outer-product-unfolds"
37+ [ benchIO "toNull" $ toNull value
38+ , benchIO "toNull3" $ toNull3 value
39+ , benchIO "concat" $ concat value
40+ , benchIO "filterAllOut" $ filterAllOut value
41+ , benchIO "filterAllIn" $ filterAllIn value
42+ , benchIO "filterSome" $ filterSome value
43+ , benchIO "breakAfterSome" $ breakAfterSome value
44+ ]
45+ ]
46+ ]
47+
48+
49+o_n_space_serial_outerProductUnfolds :: Int -> [Benchmark]
50+o_n_space_serial_outerProductUnfolds value =
51+ [ bgroup
52+ "serially"
53+ [ bgroup
54+ "outer-product-unfolds"
55+ [ benchIO "toList" $ toList value
56+ , benchIO "toListSome" $ toListSome value
57+ ]
58+ ]
59+ ]
60+
61+-------------------------------------------------------------------------------
62+-- Driver
63+-------------------------------------------------------------------------------
64+
65+main :: IO ()
66+main = do
67+ (value, cfg, benches) <- parseCLIOpts defaultStreamSize
68+ value `seq` runMode (mode cfg) cfg benches (allBenchmarks value)
69+ where
70+ allBenchmarks value =
71+ [ bgroup
72+ "o-1-space"
73+ [bgroup "unfold" (o_1_space_serial_outerProductUnfolds value)]
74+ , bgroup
75+ "o-n-space"
76+ [bgroup "unfold" (o_n_space_serial_outerProductUnfolds value)]
77+ ]
benchmark/Streamly/Benchmark/Prelude/Serial/O_1_Space.hs−1
@@ -45,7 +45,6 @@ main = do
4545 , o_1_space_serial_concatFoldable value
4646 , o_1_space_serial_concatSerial value
4747 , o_1_space_serial_outerProductStreams value
48− , o_1_space_serial_outerProductUnfolds value
4948 , o_1_space_serial_mixed value
5049 , o_1_space_serial_mixedX4 value
5150 ]
benchmark/Streamly/Benchmark/Prelude/Serial/O_n_Space.hs−1
@@ -25,7 +25,6 @@ main = do
2525 concat
2626 [ o_n_space_serial_toList size -- < 2MB
2727 , o_n_space_serial_outerProductStreams size
28− , o_n_space_serial_outerProductUnfolds size
2928 , o_n_space_wSerial_outerProductStreams size
3029 , o_n_space_serial_traversable size -- < 2MB
3130 , o_n_space_serial_foldr size
benchmark/lib/Streamly/Benchmark/Prelude.hs−32
@@ -39,7 +39,6 @@ module Streamly.Benchmark.Prelude
3939 , o_1_space_serial_concatFoldable
4040 , o_1_space_serial_concatSerial
4141 , o_1_space_serial_outerProductStreams
42− , o_1_space_serial_outerProductUnfolds
4342 , o_1_space_serial_mixed
4443 , o_1_space_serial_mixedX4
4544
@@ -51,7 +50,6 @@ module Streamly.Benchmark.Prelude
5150
5251 , o_n_space_serial_toList
5352 , o_n_space_serial_outerProductStreams
54− , o_n_space_serial_outerProductUnfolds
5553
5654 , o_n_space_wSerial_outerProductStreams
5755
@@ -129,7 +127,6 @@ import Streamly.Internal.Data.Time.Units
129127import qualified Streamly.Internal.Prelude as IP
130128
131129import qualified Streamly.Benchmark.Prelude.NestedOps as Nested
132−import qualified Streamly.Benchmark.Data.NestedUnfoldOps as NestedUnfold
133130
134131import Gauge
135132import Streamly hiding (runStream)
@@ -2024,23 +2021,6 @@ o_1_space_serial_outerProductStreams value =
20242021 ]
20252022 ]
20262023
2027−o_1_space_serial_outerProductUnfolds :: Int -> [Benchmark]
2028−o_1_space_serial_outerProductUnfolds value =
2029− [ bgroup
2030− "serially"
2031− [ bgroup
2032− "outer-product-unfolds"
2033− [ benchIO "toNull" $ NestedUnfold.toNull value
2034− , benchIO "toNull3" $ NestedUnfold.toNull3 value
2035− , benchIO "concat" $ NestedUnfold.concat value
2036− , benchIO "filterAllOut" $ NestedUnfold.filterAllOut value
2037− , benchIO "filterAllIn" $ NestedUnfold.filterAllIn value
2038− , benchIO "filterSome" $ NestedUnfold.filterSome value
2039− , benchIO "breakAfterSome" $ NestedUnfold.breakAfterSome value
2040− ]
2041− ]
2042− ]
2043−
20442024o_1_space_serial_mixed :: Int -> [Benchmark]
20452025o_1_space_serial_mixed value =
20462026 [ bgroup
@@ -2171,18 +2151,6 @@ o_n_space_serial_outerProductStreams value =
21712151 ]
21722152 ]
21732153
2174−o_n_space_serial_outerProductUnfolds :: Int -> [Benchmark]
2175−o_n_space_serial_outerProductUnfolds value =
2176− [ bgroup
2177− "serially"
2178− [ bgroup
2179− "outer-product-unfolds"
2180− [ benchIO "toList" $ NestedUnfold.toList value
2181− , benchIO "toListSome" $ NestedUnfold.toListSome value
2182− ]
2183− ]
2184− ]
2185−
21862154o_n_space_wSerial_outerProductStreams :: Int -> [Benchmark]
21872155o_n_space_wSerial_outerProductStreams value =
21882156 [ bgroup
benchmark/streamly-benchmarks.cabal+13−1
@@ -139,7 +139,6 @@ library lib-prelude
139139 Streamly.Benchmark.Prelude
140140 other-modules: Streamly.Benchmark.Common
141141 , Streamly.Benchmark.Prelude.NestedOps
142− , Streamly.Benchmark.Data.NestedUnfoldOps
143142 -- XXX GHCJS build fails for this library.
144143 if impl(ghcjs)
145144 buildable: False
@@ -236,6 +235,19 @@ benchmark fold
236235 else
237236 buildable: True
238237
238+benchmark unfold
239+ import: bench-options
240+ type: exitcode-stdio-1.0
241+ ghc-options: -rtsopts
242+ hs-source-dirs: ., Streamly/Benchmark/Data
243+ main-is: Unfold.hs
244+ other-modules: Streamly.Benchmark.Data.NestedUnfoldOps
245+ if impl(ghcjs)
246+ buildable: False
247+ else
248+ buildable: True
249+
250+
239251-------------------------------------------------------------------------------
240252-- Raw Streams
241253-------------------------------------------------------------------------------