on master help sign in
Move unfold benchmarks out of prelude. Make a seperate exec.
633e88fadithyaov
@@ -4,6 +4,7 @@ SERIAL_O_1="linear base"
4SERIAL_O_n="serial-o-n-heap serial-o-n-stack serial-o-n-space \
4SERIAL_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"
5 base-o-n-heap base-o-n-stack base-o-n-space"
6FOLD_BENCHMARKS="fold-o-1-space fold-o-n-heap"
6FOLD_BENCHMARKS="fold-o-1-space fold-o-n-heap"
7+UNFOLD_BENCHMARKS="unfold-o-1-space unfold-o-n-space"
7
8
8SERIAL_BENCHMARKS="$SERIAL_O_1 $SERIAL_O_n $FOLD_BENCHMARKS"
9SERIAL_BENCHMARKS="$SERIAL_O_1 $SERIAL_O_n $FOLD_BENCHMARKS"
9# parallel benchmark-suite is separated because we run it with a higher
10# parallel benchmark-suite is separated because we run it with a higher
@@ -27,6 +28,8 @@ bench_rts_opts () {
27 case "$1" in
28 case "$1" in
28 "fold-o-1-space") echo -n "-T -K36K -M16M" ;;
29 "fold-o-1-space") echo -n "-T -K36K -M16M" ;;
29 "fold-o-n-heap") echo -n "-T -K36K -M128M" ;;
30 "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" ;;
30 *) echo -n "" ;;
33 *) echo -n "" ;;
31 esac
34 esac
32}
35}
@@ -36,6 +39,8 @@ bench_exec () {
36 case "$1" in
39 case "$1" in
37 "fold-o-1-space") echo -n "fold" ;;
40 "fold-o-1-space") echo -n "fold" ;;
38 "fold-o-n-heap") echo -n "fold" ;;
41 "fold-o-n-heap") echo -n "fold" ;;
42+ "unfold-o-1-space") echo -n "unfold" ;;
43+ "unfold-o-n-space") echo -n "unfold" ;;
39 *) echo -n "$1" ;;
44 *) echo -n "$1" ;;
40 esac
45 esac
41}
46}
@@ -45,6 +50,8 @@ bench_gauge_opts () {
45 case "$1" in
50 case "$1" in
46 "fold-o-1-space") echo -n "-m prefix o-1-space" ;;
51 "fold-o-1-space") echo -n "-m prefix o-1-space" ;;
47 "fold-o-n-heap") echo -n "-m prefix o-n-heap" ;;
52 "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" ;;
48 *) echo -n "" ;;
55 *) echo -n "" ;;
49 esac
56 esac
50}
57}
benchmark/Chart.hs+14
@@ -40,6 +40,8 @@ data BenchType
40 | Adaptive
40 | Adaptive
41 | FoldO1Space
41 | FoldO1Space
42 | FoldOnHeap
42 | FoldOnHeap
43+ | UnfoldO1Space
44+ | UnfoldOnSpace
43 deriving Show
45 deriving Show
44
46
45data Options = Options
47data Options = Options
@@ -90,6 +92,8 @@ parseBench = do
90 Just "adaptive" -> setBenchType Adaptive
92 Just "adaptive" -> setBenchType Adaptive
91 Just "fold-o-1-space" -> setBenchType FoldO1Space
93 Just "fold-o-1-space" -> setBenchType FoldO1Space
92 Just "fold-o-n-heap" -> setBenchType FoldOnHeap
94 Just "fold-o-n-heap" -> setBenchType FoldOnHeap
95+ Just "unfold-o-1-space" -> setBenchType UnfoldO1Space
96+ Just "unfold-o-n-space" -> setBenchType UnfoldOnSpace
93 Just str -> do
97 Just str -> do
94 liftIO $ putStrLn $ "unrecognized benchmark type " <> str
98 liftIO $ putStrLn $ "unrecognized benchmark type " <> str
95 mzero
99 mzero
@@ -423,3 +427,13 @@ main = do
423 (makeGraphs "fold-o-n-heap")
427 (makeGraphs "fold-o-n-heap")
424 "charts/fold-o-n-heap/results.csv"
428 "charts/fold-o-n-heap/results.csv"
425 "charts/fold-o-n-heap"
429 "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
45 , o_1_space_serial_concatFoldable value
45 , o_1_space_serial_concatFoldable value
46 , o_1_space_serial_concatSerial value
46 , o_1_space_serial_concatSerial value
47 , o_1_space_serial_outerProductStreams value
47 , o_1_space_serial_outerProductStreams value
48− , o_1_space_serial_outerProductUnfolds value
49 , o_1_space_serial_mixed value
48 , o_1_space_serial_mixed value
50 , o_1_space_serial_mixedX4 value
49 , o_1_space_serial_mixedX4 value
51 ]
50 ]
benchmark/Streamly/Benchmark/Prelude/Serial/O_n_Space.hs−1
@@ -25,7 +25,6 @@ main = do
25 concat
25 concat
26 [ o_n_space_serial_toList size -- < 2MB
26 [ o_n_space_serial_toList size -- < 2MB
27 , o_n_space_serial_outerProductStreams size
27 , o_n_space_serial_outerProductStreams size
28− , o_n_space_serial_outerProductUnfolds size
29 , o_n_space_wSerial_outerProductStreams size
28 , o_n_space_wSerial_outerProductStreams size
30 , o_n_space_serial_traversable size -- < 2MB
29 , o_n_space_serial_traversable size -- < 2MB
31 , o_n_space_serial_foldr size
30 , o_n_space_serial_foldr size
benchmark/lib/Streamly/Benchmark/Prelude.hs−32
@@ -39,7 +39,6 @@ module Streamly.Benchmark.Prelude
39 , o_1_space_serial_concatFoldable
39 , o_1_space_serial_concatFoldable
40 , o_1_space_serial_concatSerial
40 , o_1_space_serial_concatSerial
41 , o_1_space_serial_outerProductStreams
41 , o_1_space_serial_outerProductStreams
42− , o_1_space_serial_outerProductUnfolds
43 , o_1_space_serial_mixed
42 , o_1_space_serial_mixed
44 , o_1_space_serial_mixedX4
43 , o_1_space_serial_mixedX4
45
44
@@ -51,7 +50,6 @@ module Streamly.Benchmark.Prelude
51
50
52 , o_n_space_serial_toList
51 , o_n_space_serial_toList
53 , o_n_space_serial_outerProductStreams
52 , o_n_space_serial_outerProductStreams
54− , o_n_space_serial_outerProductUnfolds
55
53
56 , o_n_space_wSerial_outerProductStreams
54 , o_n_space_wSerial_outerProductStreams
57
55
@@ -129,7 +127,6 @@ import Streamly.Internal.Data.Time.Units
129import qualified Streamly.Internal.Prelude as IP
127import qualified Streamly.Internal.Prelude as IP
130
128
131import qualified Streamly.Benchmark.Prelude.NestedOps as Nested
129import qualified Streamly.Benchmark.Prelude.NestedOps as Nested
132−import qualified Streamly.Benchmark.Data.NestedUnfoldOps as NestedUnfold
133
130
134import Gauge
131import Gauge
135import Streamly hiding (runStream)
132import Streamly hiding (runStream)
@@ -2024,23 +2021,6 @@ o_1_space_serial_outerProductStreams value =
2024 ]
2021 ]
2025 ]
2022 ]
2026
2023
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−
2044o_1_space_serial_mixed :: Int -> [Benchmark]
2024o_1_space_serial_mixed :: Int -> [Benchmark]
2045o_1_space_serial_mixed value =
2025o_1_space_serial_mixed value =
2046 [ bgroup
2026 [ bgroup
@@ -2171,18 +2151,6 @@ o_n_space_serial_outerProductStreams value =
2171 ]
2151 ]
2172 ]
2152 ]
2173
2153
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−
2186o_n_space_wSerial_outerProductStreams :: Int -> [Benchmark]
2154o_n_space_wSerial_outerProductStreams :: Int -> [Benchmark]
2187o_n_space_wSerial_outerProductStreams value =
2155o_n_space_wSerial_outerProductStreams value =
2188 [ bgroup
2156 [ bgroup
benchmark/streamly-benchmarks.cabal+13−1
@@ -139,7 +139,6 @@ library lib-prelude
139 Streamly.Benchmark.Prelude
139 Streamly.Benchmark.Prelude
140 other-modules: Streamly.Benchmark.Common
140 other-modules: Streamly.Benchmark.Common
141 , Streamly.Benchmark.Prelude.NestedOps
141 , Streamly.Benchmark.Prelude.NestedOps
142− , Streamly.Benchmark.Data.NestedUnfoldOps
143 -- XXX GHCJS build fails for this library.
142 -- XXX GHCJS build fails for this library.
144 if impl(ghcjs)
143 if impl(ghcjs)
145 buildable: False
144 buildable: False
@@ -236,6 +235,19 @@ benchmark fold
236 else
235 else
237 buildable: True
236 buildable: True
238
237
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+
239-------------------------------------------------------------------------------
251-------------------------------------------------------------------------------
240-- Raw Streams
252-- Raw Streams
241-------------------------------------------------------------------------------
253-------------------------------------------------------------------------------