on master help sign in
Fix parser benchmark namespace and RTS options

Also, rename the benchmark modules to reflect source module hierarchy.

commitc2def514f9569ff7aa59cd83dcba22ca71202638 authorHarendra Kumar <harendra@composewell.com> dateWed 3 Jun 2020, 13:10 (6 years ago) parent0b83f5d
6 files changed+81−96
bench.sh+23−11 benchmark/Chart.hs+4−23 benchmark/Streamly/Benchmark/Data/Parser.hs+13−14 benchmark/Streamly/Benchmark/Data/ParserD.hs → benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+18−21 benchmark/Streamly/Benchmark/Data/ParserK.hs → benchmark/Streamly/Benchmark/Data/Parser/ParserK.hs+11−12 benchmark/streamly-benchmarks.cabal+12−15
bench.sh+23−11
@@ -1,22 +1,25 @@
11#!/bin/bash
22
3−base_grp="\
3+# Note "_grp" and "_cmp" suffixes are special, do not rename them to something
4+# else.
5+
6+base_stream_grp="\
47 Data.Stream.StreamD \
58 Data.Stream.StreamK \
69 Data.Stream.StreamDK"
710SERIAL_O_1="linear"
811SERIAL_O_n="serial-o-n-heap serial-o-n-stack serial-o-n-space"
912UNFOLD_BENCHMARKS="unfold-o-1-space unfold-o-n-space"
10−serial_grp="\
11− $SERIAL_O_1 \
12− $SERIAL_O_n \
13− Data.Fold"
14−
13+serial_grp="$SERIAL_O_1 $SERIAL_O_n"
1514# parallel benchmark-suite is separated because we run it with a higher
1615# heap size limit.
1716concurrent_grp="linear-async linear-rate nested-concurrent parallel concurrent adaptive"
17+
1818array_grp="Memory.Array Data.Array Data.Prim.Array Data.SmallArray"
1919
20+base_parser_grp="Data.Parser.ParserD Data.Parser.ParserK"
21+parser_grp="Data.Fold Data.Parser"
22+
2023# XXX We can include SERIAL_O_1 here once "base" also supports --stream-size
2124infinite_grp="linear linear-async linear-rate nested-concurrent"
2225finite_grp="$SERIAL_O_n $array_grp fileio parallel concurrent adaptive"
@@ -28,14 +31,16 @@ QUICK_BENCHMARKS="linear-rate concurrent adaptive fileio"
2831# *_cmp denotes a comparison benchmarks, the benchmarks provided in *_cmp
2932# variables are compared with each other
3033array_cmp="Memory.Array Data.Prim.Array Data.Array"
31−base_cmp="Data.Stream.StreamD Data.Stream.StreamK"
32−COMPARISONS="array_cmp base_cmp"
34+base_stream_cmp="Data.Stream.StreamD Data.Stream.StreamK"
35+base_parser_cmp=$base_parser_grp
36+COMPARISONS="array_cmp base_stream_cmp base_parser_cmp"
3337
38+# All high level benchmarks
3439all_grp="\
35− $base_grp \
3640 $serial_grp \
3741 $concurrent_grp \
38− $array_grp"
42+ $array_grp \
43+ $parser_grp"
3944
4045ALL_BENCH_GROUPS="\
4146 all_grp \
@@ -43,7 +48,9 @@ ALL_BENCH_GROUPS="\
4348 concurrent_grp \
4449 array_grp \
4550 infinite_grp \
46− finite_grp"
51+ finite_grp \
52+ base_stream_grp \
53+ base_parser_grp"
4754
4855# RTS options that go inside +RTS and -RTS while running the benchmark.
4956bench_rts_opts () {
@@ -147,6 +154,11 @@ print_help () {
147154 echo "--quick: Faster results, useful for longer benchmarks"
148155 echo "--cabal-build-flags: Pass any cabal builds flags to be used for build"
149156 echo
157+ echo "When specific space complexity group is chosen then (and only then) "
158+ echo "RTS memory restrictions are used accordingly. For example, "
159+ echo "bench.sh --benchmarks Data.Parser -- Data.Parser/o-1-space "
160+ echo "restricts Heap/Stack space for O(1) characterstics"
161+ echo
150162 echo "When using --compare, by default comparative chart of HEAD^ vs HEAD"
151163 echo "commit is generated, in the 'charts' directory."
152164 echo "Use --base and --candidate to select the commits to compare."
benchmark/Chart.hs+4−23
@@ -28,9 +28,6 @@ data BenchType
2828 | LinearAsync
2929 | LinearRate
3030 | NestedConcurrent
31− | ParserD
32− | ParserK
33− | Parser
3431 | FileIO
3532 | Concurrent
3633 | Parallel
@@ -44,7 +41,7 @@ data Options = Options
4441 , benchType :: BenchType
4542 } deriving Show
4643
47−defaultOptions = Options False False Linear
44+defaultOptions = Options False Linear
4845
4946setGenGraphs val = do
5047 (args, opts) <- get
@@ -70,9 +67,6 @@ parseBench = do
7067 Just "linear-async" -> setBenchType LinearAsync
7168 Just "linear-rate" -> setBenchType LinearRate
7269 Just "nested-concurrent" -> setBenchType NestedConcurrent
73− Just "parserD" -> setBenchType ParserD
74− Just "parserK" -> setBenchType ParserK
75− Just "parser" -> setBenchType Parser
7670 Just "fileio" -> setBenchType FileIO
7771 Just "concurrent" -> setBenchType Concurrent
7872 Just "parallel" -> setBenchType Parallel
@@ -226,9 +220,11 @@ showComparisons Options{..} cfg inp out =
226220
227221 where
228222
223+ dropComponent = dropWhile (== '/') . dropWhile (/= '/')
224+
229225 classifyComparison b = Just $
230226 ( takeWhile (/= '/') b
231− , dropWhile (== '/') $ dropWhile (/= '/') b
227+ , dropComponent b
232228 )
233229
234230------------------------------------------------------------------------------
@@ -291,21 +287,6 @@ main = do
291287 (makeStreamComparisonGraphs "nested-concurrent" nestedBenchPrefixes)
292288 "charts/nested-concurrent/results.csv"
293289 "charts/nested-concurrent"
294− ParserD -> benchShow opts cfg
295− { title = Just "ParserD" }
296− (makeGraphs "parserD")
297− "charts/parserD/results.csv"
298− "charts/parserD"
299− ParserK -> benchShow opts cfg
300− { title = Just "ParserK" }
301− (makeGraphs "parserK")
302− "charts/parserK/results.csv"
303− "charts/parserK"
304− Parser -> benchShow opts cfg
305− { title = Just "Parser" }
306− (makeGraphs "parser")
307− "charts/parser/results.csv"
308− "charts/parser"
309290 FileIO -> benchShow opts cfg
310291 { title = Just "File IO" }
311292 (makeGraphs "fileIO")
benchmark/Streamly/Benchmark/Data/Parser.hs+13−14
@@ -221,8 +221,11 @@ parseIterate =
221221-- Benchmarks
222222-------------------------------------------------------------------------------
223223
224−o_1_space_serial_parse :: Int -> [Benchmark]
225−o_1_space_serial_parse value =
224+moduleName :: String
225+moduleName = "Data.Parser"
226+
227+o_1_space_serial :: Int -> [Benchmark]
228+o_1_space_serial value =
226229 [ benchIOSink value "any" $ any value
227230 , benchIOSink value "all" $ all value
228231 , benchIOSink value "take" $ take value
@@ -242,8 +245,8 @@ o_1_space_serial_parse value =
242245 , benchIOSink value "parseIterate" parseIterate
243246 ]
244247
245−o_n_heap_serial_parse :: Int -> [Benchmark]
246−o_n_heap_serial_parse value =
248+o_n_heap_serial :: Int -> [Benchmark]
249+o_n_heap_serial value =
247250 [
248251 -- lookahead benchmark holds the entire input till end
249252 benchIOSink value "lookAhead" $ lookAhead value
@@ -278,16 +281,12 @@ main = do
278281 where
279282
280283 allBenchmarks value =
281− [ bgroup "o-1-space"
282− [ bgroup "parser" $ concat
283− [
284− o_1_space_serial_parse value
285− ]
284+ [ bgroup (o_1_space_prefix moduleName) $ concat
285+ [
286+ o_1_space_serial value
286287 ]
287− , bgroup "o-n-heap"
288− [ bgroup "parser" $ concat
289− [
290− o_n_heap_serial_parse value
291− ]
288+ , bgroup (o_n_heap_prefix moduleName) $ concat
289+ [
290+ o_n_heap_serial value
292291 ]
293292 ]
benchmark/Streamly/Benchmark/Data/ParserD.hs → benchmark/Streamly/Benchmark/Data/Parser/ParserD.hsrenamed+18−21
@@ -177,8 +177,11 @@ choice value =
177177-- Benchmarks
178178-------------------------------------------------------------------------------
179179
180−o_1_space_serial_parse :: Int -> [Benchmark]
181−o_1_space_serial_parse value =
180+moduleName :: String
181+moduleName = "Data.Parser.ParserD"
182+
183+o_1_space_serial :: Int -> [Benchmark]
184+o_1_space_serial value =
182185 [ benchIOSink value "any" $ any value
183186 , benchIOSink value "all" $ all value
184187 , benchIOSink value "take" $ take value
@@ -193,8 +196,8 @@ o_1_space_serial_parse value =
193196 , benchIOSink value "longest (all,any)" $ longestAllAny value
194197 ]
195198
196−o_n_heap_serial_parse :: Int -> [Benchmark]
197−o_n_heap_serial_parse value =
199+o_n_heap_serial :: Int -> [Benchmark]
200+o_n_heap_serial value =
198201 [
199202 -- lookahead benchmark holds the entire input till end
200203 benchIOSink value "lookAhead" $ lookAhead value
@@ -206,8 +209,8 @@ o_n_heap_serial_parse value =
206209 ]
207210
208211-- accumulate results in a list in IO
209−o_n_space_serial_parse :: Int -> [Benchmark]
210−o_n_space_serial_parse value =
212+o_n_space_serial :: Int -> [Benchmark]
213+o_n_space_serial value =
211214 [ benchIOSink value "sequenceA/100" $ sequenceA (value `div` 100)
212215 , benchIOSink value "sequenceA_/100" $ sequenceA_ (value `div` 100)
213216 , benchIOSink value "sequence/100" $ sequence (value `div` 100)
@@ -226,22 +229,16 @@ main = do
226229 where
227230
228231 allBenchmarks value =
229− [ bgroup "o-1-space"
230− [ bgroup "parser" $ concat
231− [
232− o_1_space_serial_parse value
233− ]
232+ [ bgroup (o_1_space_prefix moduleName) $ concat
233+ [
234+ o_1_space_serial value
234235 ]
235− , bgroup "o-n-heap"
236− [ bgroup "parser" $ concat
237− [
238− o_n_heap_serial_parse value
239− ]
236+ , bgroup (o_n_heap_prefix moduleName) $ concat
237+ [
238+ o_n_heap_serial value
240239 ]
241− , bgroup "o-n-space"
242− [ bgroup "parser" $ concat
243− [
244− o_n_space_serial_parse value
245− ]
240+ , bgroup (o_n_space_prefix moduleName) $ concat
241+ [
242+ o_n_space_serial value
246243 ]
247244 ]
benchmark/Streamly/Benchmark/Data/ParserK.hs → benchmark/Streamly/Benchmark/Data/Parser/ParserK.hsrenamed+11−12
@@ -121,15 +121,18 @@ choice value =
121121-- Benchmarks
122122-------------------------------------------------------------------------------
123123
124−o_1_space_serial_parse :: Int -> [Benchmark]
125−o_1_space_serial_parse value =
124+moduleName :: String
125+moduleName = "Data.Parser.ParserK"
126+
127+o_1_space_serial :: Int -> [Benchmark]
128+o_1_space_serial value =
126129 [ benchIOSink value "any" $ anyK value
127130 , benchIOSink value "splitApp" $ splitApp value
128131 ]
129132
130133-- O(n) heap beacuse of accumulation of the list in strict IO monad?
131−o_n_heap_serial_parse :: Int -> [Benchmark]
132−o_n_heap_serial_parse value =
134+o_n_heap_serial :: Int -> [Benchmark]
135+o_n_heap_serial value =
133136 [ benchIOSink value "sequenceA" $ sequenceA value
134137 , benchIOSink value "sequenceA_" $ sequenceA_ value
135138 , benchIOSink value "sequence" $ sequence value
@@ -150,14 +153,10 @@ main = do
150153 where
151154
152155 allBenchmarks value =
153− [ bgroup "o-1-space"
154− [ bgroup "parserK" $ concat
155− [ o_1_space_serial_parse value
156− ]
156+ [ bgroup (o_1_space_prefix moduleName) $ concat
157+ [ o_1_space_serial value
157158 ]
158− , bgroup "o-n-heap"
159− [ bgroup "parserK" $ concat
160− [ o_n_heap_serial_parse value
161− ]
159+ , bgroup (o_n_heap_prefix moduleName) $ concat
160+ [ o_n_heap_serial value
162161 ]
163162 ]
benchmark/streamly-benchmarks.cabal+12−15
@@ -190,32 +190,31 @@ benchmark serial
190190 build-depends: lib-prelude
191191 buildable: True
192192
193−benchmark Data.Fold
193+benchmark unfold
194194 import: bench-options
195195 type: exitcode-stdio-1.0
196− hs-source-dirs: Streamly/Benchmark/Data
197− main-is: Fold.hs
196+ hs-source-dirs: ., Streamly/Benchmark/Data
197+ main-is: Unfold.hs
198+ other-modules: Streamly.Benchmark.Data.NestedUnfoldOps
198199 if impl(ghcjs)
199200 buildable: False
200201 else
201202 buildable: True
202203
203−benchmark unfold
204+benchmark Data.Fold
204205 import: bench-options
205206 type: exitcode-stdio-1.0
206− hs-source-dirs: ., Streamly/Benchmark/Data
207− main-is: Unfold.hs
208− other-modules: Streamly.Benchmark.Data.NestedUnfoldOps
207+ hs-source-dirs: Streamly/Benchmark/Data
208+ main-is: Fold.hs
209209 if impl(ghcjs)
210210 buildable: False
211211 else
212212 buildable: True
213213
214−benchmark parserD
214+benchmark Data.Parser.ParserD
215215 import: bench-options
216216 type: exitcode-stdio-1.0
217− ghc-options: -with-rtsopts "-T -K64K -M16M"
218− hs-source-dirs: ., Streamly/Benchmark/Data
217+ hs-source-dirs: Streamly/Benchmark/Data/Parser
219218 main-is: ParserD.hs
220219 if impl(ghcjs)
221220 buildable: False
@@ -223,11 +222,10 @@ benchmark parserD
223222 buildable: True
224223 build-depends: exceptions >= 0.8 && < 0.11
225224
226−benchmark parserK
225+benchmark Data.Parser.ParserK
227226 import: bench-options
228227 type: exitcode-stdio-1.0
229− ghc-options: -with-rtsopts "-T -K128K -M32M"
230− hs-source-dirs: Streamly/Benchmark/Data
228+ hs-source-dirs: Streamly/Benchmark/Data/Parser
231229 main-is: ParserK.hs
232230 if impl(ghcjs)
233231 buildable: False
@@ -235,10 +233,9 @@ benchmark parserK
235233 buildable: True
236234 build-depends: exceptions >= 0.8 && < 0.11
237235
238−benchmark parser
236+benchmark Data.Parser
239237 import: bench-options
240238 type: exitcode-stdio-1.0
241− ghc-options: -with-rtsopts "-T -K128K -M32M"
242239 hs-source-dirs: Streamly/Benchmark/Data
243240 main-is: Parser.hs
244241 if impl(ghcjs)