@@ -1,5 +1,19 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
3+# Note that this script is used in the "streamly" package as well as
4+# in "streaming-benchmarks" package. Any changes to the script should be
5+# generic enough so that it works in both the cases.
7+# Customization options
8+BENCHMARK_DIR=benchmark
9+BENCHMARK_PACKAGE_NAME=streamly-benchmarks
10+BENCHMARK_PACKAGE_VERSION=0.0.0
13+DEFAULT_FIELDS="allocated cputime bytescopied"
15+#------------------------------------------------------------------------------
3set -o pipefail
17set -o pipefail
5SCRIPT_DIR=$(cd `dirname $0`; pwd)
19SCRIPT_DIR=$(cd `dirname $0`; pwd)
@@ -13,6 +27,7 @@ print_help () {
13 echo " [--prefix <benchmark name prefix to match>"
27 echo " [--prefix <benchmark name prefix to match>"
14 echo " [--fields <"field1 field2 ..." | help>]"
28 echo " [--fields <"field1 field2 ..." | help>]"
15 echo " [--sort-by-name]"
29 echo " [--sort-by-name]"
16 echo " [--graphs]"
31 echo " [--graphs]"
17 echo " [--no-measure]"
32 echo " [--no-measure]"
18 echo " [--append]"
33 echo " [--append]"
@@ -25,10 +40,11 @@ print_help () {
25 echo " [--with-compiler <compiler exe name>]"
40 echo " [--with-compiler <compiler exe name>]"
26 echo " [--cabal-build-options <options>]"
41 echo " [--cabal-build-options <options>]"
27 echo " [--rtsopts <opts>]"
42 echo " [--rtsopts <opts>]"
28− echo " [--compare] [--base <commit>] [--candidate <commit>]"
43+ echo " [--commit-compare] [--base <commit>] [--candidate <commit>]"
29 echo " -- <gauge options or benchmarks>"
44 echo " -- <gauge options or benchmarks>"
31 echo "--benchmarks: benchmarks to run, use 'help' for list of benchmarks"
46 echo "--benchmarks: benchmarks to run, use 'help' for list of benchmarks"
47+ echo "--compare: compare the specified benchmarks with each other"
32 echo "--fields: measurement fields to report, use 'help' for a list"
48 echo "--fields: measurement fields to report, use 'help' for a list"
33 echo "--graphs: Generate graphical reports"
49 echo "--graphs: Generate graphical reports"
34 echo "--no-measure: Don't run benchmarks, run reports from previous results"
50 echo "--no-measure: Don't run benchmarks, run reports from previous results"
@@ -46,7 +62,7 @@ print_help () {
46 echo "bench.sh --benchmarks Data.Parser -- Data.Parser/o-1-space "
62 echo "bench.sh --benchmarks Data.Parser -- Data.Parser/o-1-space "
47 echo "restricts Heap/Stack space for O(1) characterstics"
63 echo "restricts Heap/Stack space for O(1) characterstics"
49− echo "When using --compare, by default comparative chart of HEAD^ vs HEAD"
65+ echo "When using --commit-compare, by default comparative chart of HEAD^ vs HEAD"
50 echo "commit is generated, in the 'charts' directory."
66 echo "commit is generated, in the 'charts' directory."
51 echo "Use --base and --candidate to select the commits to compare."
67 echo "Use --base and --candidate to select the commits to compare."
@@ -99,9 +115,9 @@ build_report_prog() {
100 echo "Building bench-report executables"
116 echo "Building bench-report executables"
101 BUILD_ONCE=1
117 BUILD_ONCE=1
102− pushd benchmark/bench-report
118+ pushd $BENCHMARK_DIR/bench-report
103 local cmd
119 local cmd
104− cmd="$CABAL_EXECUTABLE install --installdir ../../bin bench-report"
120+ cmd="$CABAL_EXECUTABLE install --installdir $SCRIPT_DIR bench-report"
105 if test "$USE_NIX" -eq 0
121 if test "$USE_NIX" -eq 0
107 $cmd || die "bench-report build failed"
123 $cmd || die "bench-report build failed"
@@ -240,14 +256,14 @@ run_benches_comparing() {
240 git checkout "$BASE" || die "Checkout of base commit [$BASE] failed"
256 git checkout "$BASE" || die "Checkout of base commit [$BASE] failed"
242 $BUILD_BENCH || die "build failed"
258 $BUILD_BENCH || die "build failed"
243− run_bench_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
259+ run_bench_targets $BENCHMARK_PACKAGE_NAME b "$bench_list" target_exe_extra_args
245 echo "Checking out candidate commit [$CANDIDATE] for benchmarking"
261 echo "Checking out candidate commit [$CANDIDATE] for benchmarking"
246 git checkout "$CANDIDATE" || \
262 git checkout "$CANDIDATE" || \
247 die "Checkout of candidate [$CANDIDATE] commit failed"
263 die "Checkout of candidate [$CANDIDATE] commit failed"
249 $BUILD_BENCH || die "build failed"
265 $BUILD_BENCH || die "build failed"
250− run_bench_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
266+ run_bench_targets $BENCHMARK_PACKAGE_NAME b "$bench_list" target_exe_extra_args
251 # XXX reset back to the original commit
267 # XXX reset back to the original commit
@@ -269,9 +285,9 @@ run_measurements() {
269 backup_output_file $i
285 backup_output_file $i
272− if test "$COMPARE" = "0"
288+ if test "$COMMIT_COMPARE" = "0"
274− run_bench_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
290+ run_bench_targets $BENCHMARK_PACKAGE_NAME b "$bench_list" target_exe_extra_args
276 run_benches_comparing "$bench_list"
292 run_benches_comparing "$bench_list"
@@ -300,16 +316,21 @@ run_reports() {
301cd $SCRIPT_DIR/..
317cd $SCRIPT_DIR/..
304USE_GIT_CABAL=1
319USE_GIT_CABAL=1
306set_common_vars
321set_common_vars
308−DEFAULT_FIELDS="allocated bytescopied cputime"
323+COMMON_FIELDS="allocated bytescopied cputime maxrss"
324+if test "$USE_GAUGE" -eq 1
309−ALL_FIELDS="$FIELDS time cycles utime stime minflt majflt nvcsw nivcsw"
326+ ALL_FIELDS="$COMMON_FIELDS time cycles utime stime minflt majflt nvcsw nivcsw"
328+ ALL_FIELDS="$COMMON_FIELDS"
310FIELDS=$DEFAULT_FIELDS
330FIELDS=$DEFAULT_FIELDS
314CANDIDATE=
335CANDIDATE=
@@ -348,6 +369,7 @@ do
348 --slow) SLOW=1; shift ;;
369 --slow) SLOW=1; shift ;;
349 --quick) QUICK_MODE=1; shift ;;
370 --quick) QUICK_MODE=1; shift ;;
350 --compare) COMPARE=1; shift ;;
371 --compare) COMPARE=1; shift ;;
372+ --commit-compare) COMMIT_COMPARE=1; shift ;;
351 --raw) RAW=1; shift ;;
373 --raw) RAW=1; shift ;;
352 --append) APPEND=1; shift ;;
374 --append) APPEND=1; shift ;;
353 --long) LONG=1; shift ;;
375 --long) LONG=1; shift ;;
@@ -443,7 +465,7 @@ fi
443BUILD_BENCH="$CABAL_EXECUTABLE v2-build $BUILD_FLAGS $CABAL_BUILD_OPTIONS --enable-benchmarks"
465BUILD_BENCH="$CABAL_EXECUTABLE v2-build $BUILD_FLAGS $CABAL_BUILD_OPTIONS --enable-benchmarks"
444if test "$MEASURE" = "1"
466if test "$MEASURE" = "1"
446− run_build "$BUILD_BENCH" streamly-benchmarks bench "$TARGETS"
468+ run_build "$BUILD_BENCH" $BENCHMARK_PACKAGE_NAME bench "$TARGETS"
447 run_measurements "$TARGETS"
469 run_measurements "$TARGETS"
@@ -451,20 +473,38 @@ fi
451# Run reports
473# Run reports
452#-----------------------------------------------------------------------------
474#-----------------------------------------------------------------------------
454−COMPARISON_REPORTS=""
476+# $1: var name
455−for i in $COMPARISONS
477+build_comparison_results () {
457− if test "$(has_item "$TARGETS_ORIG" $i)" = $i
479+ local constituents
459− COMPARISON_REPORTS="$COMPARISON_REPORTS $i"
481+ name=$1
460− mkdir -p "charts/$i"
461− constituents=$(eval "echo -n \$${i}")
482+ constituents=$(eval "echo -n \$${name}")
483+ mkdir -p "charts/$name"
462− dest_file="charts/$i/results.csv"
484+ dest_file="charts/$name/results.csv"
463 : > $dest_file
485 : > $dest_file
464 for j in $constituents
486 for j in $constituents
466 cat "charts/$j/results.csv" >> $dest_file
488 cat "charts/$j/results.csv" >> $dest_file
492+if test "$COMPARE" -eq 1
494+ DYN_CMP_GRP="$(echo "$TARGETS" | sed -e 's/ /_/g')_cmp"
495+ eval "$DYN_CMP_GRP=\"$TARGETS\""
496+ COMPARISON_REPORTS=$DYN_CMP_GRP
497+ build_comparison_results $DYN_CMP_GRP
499+ COMPARISON_REPORTS=""
502+for i in $COMPARISONS
504+ if test "$(has_item "$TARGETS_ORIG" $i)" = $i
506+ COMPARISON_REPORTS="$COMPARISON_REPORTS $i"
507+ build_comparison_results $i
@@ -472,4 +512,8 @@ if test "$RAW" = "0"
473 run_reports "$TARGETS"
513 run_reports "$TARGETS"
474 run_reports "$COMPARISON_REPORTS"
514 run_reports "$COMPARISON_REPORTS"
515+ if test -n "$DYN_CMP_GRP"
517+ rm -rf "charts/$DYN_CMP_GRP"