3SCRIPT_DIR=$(cd `dirname $0`; pwd)
6source $SCRIPT_DIR/build-lib.sh
10 echo " [--benchmarks <"bench1 bench2 ..." | help>]"
11 echo " [--fields <"field1 field2 ..." | help>]"
13 echo " [--no-measure]"
20 echo " [--cabal-build-flags <flag>]"
21 echo " [--rtsopts <opts>]"
22 echo " [--compare] [--base <commit>] [--candidate <commit>]"
23 echo " -- <gauge options or benchmarks>"
25 echo "--benchmarks: benchmarks to run, use 'help' for list of benchmarks"
26 echo "--fields: measurement fields to report, use 'help' for a list"
27 echo "--graphs: Generate graphical reports"
28 echo "--no-measure: Don't run benchmarks, run reports from previous results"
29 echo "--append: Don't overwrite previous results, append for comparison"
30 echo "--long: Use much longer stream size for infinite stream benchmarks"
31 echo "--slow: Slightly more accurate results at the expense of speed"
32 echo "--quick: Faster results, useful for longer benchmarks"
33 echo "--raw: Run the benchmarks but don't report them. This is useful when"
34 echo " you only want to work with the csv files generated."
35 echo "--cabal-build-flags: Pass any cabal builds flags to be used for build"
36 echo " e.g. --cabal-build-flags \"--flag fusion-plugin\""
38 echo "When specific space complexity group is chosen then (and only then) "
39 echo "RTS memory restrictions are used accordingly. For example, "
40 echo "bench.sh --benchmarks Data.Parser -- Data.Parser/o-1-space "
41 echo "restricts Heap/Stack space for O(1) characterstics"
43 echo "When using --compare, by default comparative chart of HEAD^ vs HEAD"
44 echo "commit is generated, in the 'charts' directory."
45 echo "Use --base and --candidate to select the commits to compare."
47 echo "Any arguments after a '--' are passed directly to gauge"
51#-----------------------------------------------------------------------------
52# Reporting utility functions
53#-----------------------------------------------------------------------------
56 echo "Comparison groups:"
66# chart is expensive to build and usually not required to be rebuilt,
67# use master branch as fallback
69 local path=$(cabal_which streamly-benchmarks x $1)
72 cabal_which_builddir dist-newstyle streamly-benchmarks x $1
79 local prog_name="chart"
81 local prog_path=$(cabal_which_report $prog_name)
82 if test -x "$prog_path"
91 local prog_name="chart"
92 local prog_path=$(cabal_which_report $prog_name)
95 if test ! -x "$prog_path" -a "$BUILD_ONCE" = "0"
97 echo "Building bench-show executables"
99 $CABAL_EXECUTABLE v2-build --flags dev chart \
100 || die "bench-show build failed"
102 elif test ! -x "$prog_path"
109build_report_progs() {
112 build_report_prog || exit 1
114 prog=$(find_report_prog) || \
115 die "Cannot find bench-show executable"
116 echo "Using bench-show executable [$prog]"
120# We run the benchmarks in isolation in a separate process so that different
121# benchmarks do not interfere with other. To enable that we need to pass the
122# benchmark exe path to gauge as an argument. Unfortunately it cannot find its
125# The path is dependent on the architecture and cabal version.
129 echo "charts/$bench_name/results.csv"
132# --min-duration 0 means exactly one iteration per sample. We use a million
133# iterations in the benchmarking code explicitly and do not use the iterations
134# done by the benchmarking tool.
136# Benchmarking tool by default discards the first iteration to remove
137# aberrations due to initial evaluations etc. We do not discard it because we
138# are anyway doing iterations in the benchmarking code and many of them so that
139# any constant factor gets amortized and anyway it is a cost that we pay in
142# We can pass --min-samples value from the command line as second argument
143# after the benchmark name in case we want to use more than one sample.
146# $2: bench executable
147target_exe_extra_args () {
151 local output_file=$(bench_output_file $bench_name)
152 mkdir -p `dirname $output_file`
154 local QUICK_OPTS="--quick --min-duration 0"
156 if test "$LONG" -eq 0
158 if test "$SLOW" -eq 0
160 if test "$QUICK_MODE" -eq 0
162 # default mode, not super quick, not slow
163 SPEED_OPTIONS="$QUICK_OPTS --min-samples 10 --time-limit 1"
165 # super quick but less accurate
166 SPEED_OPTIONS="$QUICK_OPTS --time-limit 0 --include-first-iter"
169 # Slow but more accurate mode
170 SPEED_OPTIONS="--min-duration 0"
173 # large stream size, always super quick
174 GAUGE_ARGS="$GAUGE_ARGS $bench_name/o-1-space"
175 SPEED_OPTIONS="--stream-size 10000000 $QUICK_OPTS --include-first-iter"
178 echo "$SPEED_OPTIONS \
179 --csvraw=$output_file \
181 --measure-with "$SCRIPT_DIR/bench-exec-one.sh" \
185run_benches_comparing() {
188 if test -z "$CANDIDATE"
190 CANDIDATE=$(git rev-parse HEAD)
194 # XXX Should be where the current branch is forked from master
197 echo "Comparing baseline commit [$BASE] with candidate [$CANDIDATE]"
198 echo "Checking out base commit [$BASE] for benchmarking"
199 git checkout "$BASE" || die "Checkout of base commit [$BASE] failed"
201 $BUILD_BENCH || die "build failed"
202 run_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
204 echo "Checking out candidate commit [$CANDIDATE] for benchmarking"
205 git checkout "$CANDIDATE" || \
206 die "Checkout of candidate [$CANDIDATE] commit failed"
208 $BUILD_BENCH || die "build failed"
209 run_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
210 # XXX reset back to the original commit
213backup_output_file() {
215 local output_file=$(bench_output_file $bench_name)
217 if test -e $output_file -a "$APPEND" != 1
219 mv -f -v $output_file ${output_file}.prev
228 backup_output_file $i
231 if test "$COMPARE" = "0"
233 run_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
235 run_benches_comparing "$bench_list"
241 prog=$(find_report_prog) || \
242 die "Cannot find bench-graph executable"
247 echo "Generating reports for ${i}..."
248 $prog $(test "$GRAPH" = 1 && echo "--graphs") \
249 --benchmark $i --fields "$FIELDS"
253#-----------------------------------------------------------------------------
254# Execution starts here
255#-----------------------------------------------------------------------------
262DEFAULT_FIELDS="allocated bytescopied cputime"
263ALL_FIELDS="$FIELDS time cycles utime stime minflt majflt nvcsw nivcsw"
264FIELDS=$DEFAULT_FIELDS
279#-----------------------------------------------------------------------------
281#-----------------------------------------------------------------------------
286 -h|--help|help) print_help ;;
287 # options with arguments
288 --benchmarks) shift; TARGETS=$1; shift ;;
289 --targets) shift; TARGETS=$1; shift ;;
290 --fields) shift; FIELDS=$1; shift ;;
291 --base) shift; BASE=$1; shift ;;
292 --candidate) shift; CANDIDATE=$1; shift ;;
293 --cabal-build-flags) shift; CABAL_BUILD_OPTIONS=$1; shift ;;
294 --cabal-build-options) shift; CABAL_BUILD_OPTIONS=$1; shift ;;
295 --rtsopts) shift; RTS_OPTIONS=$1; shift ;;
297 --slow) SLOW=1; shift ;;
298 --quick) QUICK_MODE=1; shift ;;
299 --compare) COMPARE=1; shift ;;
300 --raw) RAW=1; shift ;;
301 --append) APPEND=1; shift ;;
302 --long) LONG=1; shift ;;
303 --graphs) GRAPH=1; shift ;;
304 --no-measure) MEASURE=0; shift ;;
305 --dev-build) RUNNING_DEVBUILD=1; shift ;;
307 -*|--*) echo "Unknown flags: $*"; echo; print_help ;;
313#-----------------------------------------------------------------------------
315#-----------------------------------------------------------------------------
317only_real_benchmarks () {
321 for j in $COMPARISONS
328 if test "$SKIP" -eq 0
335# Requires RUNNING_DEVBUILD var
336source $SCRIPT_DIR/targets.sh
338if test "$(has_item "$TARGETS" help)" = "help"
346if test "$(has_item "$FIELDS" help)" = "help"
348 echo "Supported fields: $ALL_FIELDS"
349 echo "Default fields: $DEFAULT_FIELDS"
355 if test -n "$TARGETS"
357 echo "Cannot specify benchmarks [$TARGETS] with --long"
360 TARGETS=$infinite_grp
363DEFAULT_TARGETS="$(all_grp)"
364TARGETS=$(set_targets)
367TARGETS=$(only_real_benchmarks)
369echo "Using benchmark suites [$TARGETS]"
371#-----------------------------------------------------------------------------
372# Build reporting utility
373#-----------------------------------------------------------------------------
375# We need to build the report progs first at the current (latest) commit before
376# checking out any other commit for benchmarking.
379#-----------------------------------------------------------------------------
380# Build and run targets
381#-----------------------------------------------------------------------------
383BUILD_BENCH="$CABAL_EXECUTABLE v2-build $CABAL_BUILD_OPTIONS --enable-benchmarks"
384if test "$MEASURE" = "1"
386 run_build "$BUILD_BENCH" streamly-benchmarks bench "$TARGETS"
389 run_measurements "$TARGETS"
392#-----------------------------------------------------------------------------
394#-----------------------------------------------------------------------------
399 if test "$(has_item "$TARGETS_ORIG" $i)" = $i
401 COMPARISON_REPORTS="$COMPARISON_REPORTS $i"
403 constituents=$(eval "echo -n \$${i}")
404 dest_file="charts/$i/results.csv"
406 for j in $constituents
408 cat "charts/$j/results.csv" >> $dest_file
415 run_reports "$TARGETS"
416 run_reports "$COMPARISON_REPORTS"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list