5SCRIPT_DIR=$(cd `dirname $0`; pwd)
8source $SCRIPT_DIR/build-lib.sh
12 echo " [--benchmarks <"bench1 bench2 ..." | help>]"
13 echo " [--prefix <benchmark name prefix to match>"
14 echo " [--fields <"field1 field2 ..." | help>]"
15 echo " [--sort-by-name]"
17 echo " [--no-measure]"
24 echo " [--with-compiler <compiler exe name>]"
25 echo " [--cabal-build-options <options>]"
26 echo " [--rtsopts <opts>]"
27 echo " [--compare] [--base <commit>] [--candidate <commit>]"
28 echo " -- <gauge options or benchmarks>"
30 echo "--benchmarks: benchmarks to run, use 'help' for list of benchmarks"
31 echo "--fields: measurement fields to report, use 'help' for a list"
32 echo "--graphs: Generate graphical reports"
33 echo "--no-measure: Don't run benchmarks, run reports from previous results"
34 echo "--append: Don't overwrite previous results, append for comparison"
35 echo "--long: Use much longer stream size for infinite stream benchmarks"
36 echo "--slow: Slightly more accurate results at the expense of speed"
37 echo "--quick: Faster results, useful for longer benchmarks"
38 echo "--raw: Run the benchmarks but don't report them. This is useful when"
39 echo " you only want to work with the csv files generated."
40 echo "--cabal-build-options: Pass any cabal build options to be used for build"
41 echo " e.g. --cabal-build-options \"--flag dev\""
43 echo "When specific space complexity group is chosen then (and only then) "
44 echo "RTS memory restrictions are used accordingly. For example, "
45 echo "bench.sh --benchmarks Data.Parser -- Data.Parser/o-1-space "
46 echo "restricts Heap/Stack space for O(1) characterstics"
48 echo "When using --compare, by default comparative chart of HEAD^ vs HEAD"
49 echo "commit is generated, in the 'charts' directory."
50 echo "Use --base and --candidate to select the commits to compare."
52 echo "Any arguments after a '--' are passed directly to gauge"
56#-----------------------------------------------------------------------------
57# Reporting utility functions
58#-----------------------------------------------------------------------------
61 echo "Comparison groups:"
71# chart is expensive to build and usually not required to be rebuilt,
72# use master branch as fallback
74 local path=$(cabal_which streamly-benchmarks x $1)
77 echo "Cannot find $1 executable, trying in dist-newstyle" 1>&2
78 local path1=$(cabal_which_builddir dist-newstyle streamly-benchmarks x $1)
81 local path2="./bin/$1"
82 echo "Cannot find $1 executable, trying $path2" 1>&2
96 local prog_name="chart"
98 local prog_path=$(cabal_which_report $prog_name)
99 if test -x "$prog_path"
108 local prog_name="chart"
109 local prog_path=$(cabal_which_report $prog_name)
112 if test ! -x "$prog_path" -a "$BUILD_ONCE" = "0"
114 echo "Building bench-show executables"
116 $CABAL_EXECUTABLE v2-build --flags dev chart \
117 || die "bench-show build failed"
119 elif test ! -x "$prog_path"
126build_report_progs() {
129 build_report_prog || exit 1
131 prog=$(find_report_prog) || \
132 die "Cannot find bench-show executable"
133 echo "Using bench-show executable [$prog]"
137# We run the benchmarks in isolation in a separate process so that different
138# benchmarks do not interfere with other. To enable that we need to pass the
139# benchmark exe path to gauge as an argument. Unfortunately it cannot find its
142# The path is dependent on the architecture and cabal version.
146 echo "charts/$bench_name/results.csv"
150 local target_prog="$1"
151 local target_name="$2"
152 local output_file="$3"
155 if test "$LONG" -ne 0
157 MATCH="$target_name/o-1-space"
159 MATCH="$BENCH_PREFIX"
161 echo "name,iters,time,cycles,cpuTime,utime,stime,maxrss,minflt,majflt,nvcsw,nivcsw,allocated,numGcs,bytesCopied,mutatorWallSeconds,mutatorCpuSeconds,gcWallSeconds,gcCpuSeconds" >> $output_file
162 # keep only benchmark names with shortest prefix e.g. "a/b/c" and "a/b", we
163 # should only keep "a/b" otherwise benchmarks will run multiple times. why?
166 | while read -r name; \
167 do bin/bench-exec-one.sh "$name" "${GAUGE_ARGS[@]}" || exit 1; done \
168 || die "Benchmark execution failed."
171invoke_tasty_bench () {
172 local target_prog="$1"
173 local target_name="$2"
174 local output_file="$3"
177 if test "$LONG" -ne 0
179 MATCH="-p /$target_name\/o-1-space/"
181 if test -n "$BENCH_PREFIX"
184 local escaped_name=$(echo "$BENCH_PREFIX" | sed -e 's/\//\\\//g')
185 MATCH="-p /$escaped_name/"
188 echo "Name,cpuTime,2*Stdev (ps),Allocated,bytesCopied" >> $output_file
189 $target_prog -l $MATCH \
191 | while read -r name; \
192 do bin/bench-exec-one.sh "$name" "${GAUGE_ARGS[@]}" || exit 1; done \
193 || die "Benchmark execution failed."
197 local package_name=$1
202 target_prog=$(cabal_target_prog $package_name $component $target_name) || \
203 die "Cannot find executable for target $target_name"
205 echo "Running executable $target_name ..."
207 # Needed by bench-exec-one.sh
208 export BENCH_EXEC_PATH=$target_prog
214 local output_file=$(bench_output_file $target_name)
215 mkdir -p `dirname $output_file`
216 if test "$USE_GAUGE" -eq 0
217 then invoke_tasty_bench "$target_prog" "$target_name" "$output_file"
218 else invoke_gauge "$target_prog" "$target_name" "$output_file"
228 run_bench_target $1 $2 $i
232run_benches_comparing() {
235 if test -z "$CANDIDATE"
237 CANDIDATE=$(git rev-parse HEAD)
241 # XXX Should be where the current branch is forked from master
244 echo "Comparing baseline commit [$BASE] with candidate [$CANDIDATE]"
245 echo "Checking out base commit [$BASE] for benchmarking"
246 git checkout "$BASE" || die "Checkout of base commit [$BASE] failed"
248 $BUILD_BENCH || die "build failed"
249 run_bench_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
251 echo "Checking out candidate commit [$CANDIDATE] for benchmarking"
252 git checkout "$CANDIDATE" || \
253 die "Checkout of candidate [$CANDIDATE] commit failed"
255 $BUILD_BENCH || die "build failed"
256 run_bench_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
257 # XXX reset back to the original commit
260backup_output_file() {
262 local output_file=$(bench_output_file $bench_name)
264 if test -e $output_file -a "$APPEND" != 1
266 mv -f -v $output_file ${output_file}.prev
275 backup_output_file $i
278 if test "$COMPARE" = "0"
280 run_bench_targets streamly-benchmarks b "$bench_list" target_exe_extra_args
282 run_benches_comparing "$bench_list"
288 prog=$(find_report_prog) || \
289 die "Cannot find bench-graph executable"
294 echo "Generating reports for ${i}..."
297 $(test "$GRAPH" = 1 && echo "--graphs") \
298 $(test "$SORT_BY_NAME" = 1 && echo "--sort-by-name") \
303#-----------------------------------------------------------------------------
304# Execution starts here
305#-----------------------------------------------------------------------------
313DEFAULT_FIELDS="allocated bytescopied cputime"
314ALL_FIELDS="$FIELDS time cycles utime stime minflt majflt nvcsw nivcsw"
315FIELDS=$DEFAULT_FIELDS
331CABAL_BUILD_OPTIONS="--flag fusion-plugin "
333#-----------------------------------------------------------------------------
335#-----------------------------------------------------------------------------
340 -h|--help|help) print_help ;;
341 # options with arguments
342 --benchmarks) shift; TARGETS=$1; shift ;;
343 --targets) shift; TARGETS=$1; shift ;;
344 --prefix) shift; BENCH_PREFIX="$1"; shift ;;
345 --fields) shift; FIELDS=$1; shift ;;
346 --base) shift; BASE=$1; shift ;;
347 --candidate) shift; CANDIDATE=$1; shift ;;
348 --with-compiler) shift; CABAL_WITH_COMPILER=$1; shift ;;
349 --cabal-build-flags) shift; CABAL_BUILD_OPTIONS+=$1; shift ;;
350 --cabal-build-options) shift; CABAL_BUILD_OPTIONS+=$1; shift ;;
351 --rtsopts) shift; RTS_OPTIONS=$1; shift ;;
353 --slow) SLOW=1; shift ;;
354 --quick) QUICK_MODE=1; shift ;;
355 --compare) COMPARE=1; shift ;;
356 --raw) RAW=1; shift ;;
357 --append) APPEND=1; shift ;;
358 --long) LONG=1; shift ;;
359 --sort-by-name) SORT_BY_NAME=1; shift ;;
360 --graphs) GRAPH=1; shift ;;
361 --no-measure) MEASURE=0; shift ;;
362 --dev-build) RUNNING_DEVBUILD=1; shift ;;
363 --use-gauge) USE_GAUGE=1; shift ;;
365 *) echo "Unknown flags: $*"; echo; print_help ;;
372#-----------------------------------------------------------------------------
374#-----------------------------------------------------------------------------
376only_real_benchmarks () {
380 for j in $COMPARISONS
387 if test "$SKIP" -eq 0
394# Requires RUNNING_DEVBUILD var
395source $SCRIPT_DIR/targets.sh
397if test "$(has_item "$TARGETS" help)" = "help"
405if test "$(has_item "$FIELDS" help)" = "help"
407 echo "Supported fields: $ALL_FIELDS"
408 echo "Default fields: $DEFAULT_FIELDS"
414 if test -n "$TARGETS"
416 echo "Cannot specify benchmarks [$TARGETS] with --long"
419 TARGETS=$infinite_grp
422DEFAULT_TARGETS="$(all_grp)"
423TARGETS=$(set_targets)
426TARGETS=$(only_real_benchmarks)
428echo "Using benchmark suites [$TARGETS]"
430#-----------------------------------------------------------------------------
431# Build reporting utility
432#-----------------------------------------------------------------------------
434# We need to build the report progs first at the current (latest) commit before
435# checking out any other commit for benchmarking.
438#-----------------------------------------------------------------------------
439# Build and run targets
440#-----------------------------------------------------------------------------
442if test "$USE_GAUGE" -eq 1
444 BUILD_FLAGS="--flag use-gauge"
447BUILD_BENCH="$CABAL_EXECUTABLE v2-build $BUILD_FLAGS $CABAL_BUILD_OPTIONS --enable-benchmarks"
448if test "$MEASURE" = "1"
450 run_build "$BUILD_BENCH" streamly-benchmarks bench "$TARGETS"
451 run_measurements "$TARGETS"
454#-----------------------------------------------------------------------------
456#-----------------------------------------------------------------------------
461 if test "$(has_item "$TARGETS_ORIG" $i)" = $i
463 COMPARISON_REPORTS="$COMPARISON_REPORTS $i"
465 constituents=$(eval "echo -n \$${i}")
466 dest_file="charts/$i/results.csv"
468 for j in $constituents
470 cat "charts/$j/results.csv" >> $dest_file
477 run_reports "$TARGETS"
478 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