on master help sign in
Markdown (and JSON) reports
b12503aDavid Peter
tests/benchmarks/.gitignorenew file+1
@@ -0,0 +1 @@
1+/benchmark-results
tests/benchmarks/run-benchmarks.sh+43−19
@@ -1,4 +1,5 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2+
2cd "$(dirname "${BASH_SOURCE[0]}")" || exit
3cd "$(dirname "${BASH_SOURCE[0]}")" || exit
3
4
4# Check that Hyperfine is installed.
5# Check that Hyperfine is installed.
@@ -19,16 +20,28 @@ get_cargo_target_dir() {
19 cargo metadata --no-deps --format-version 1 | jq -r .target_directory
20 cargo metadata --no-deps --format-version 1 | jq -r .target_directory
20}
21}
21
22
23+heading() {
24+ bold=$(tput bold)$(tput setaf 220)
25+ normal=$(tput sgr0)
26+ echo
27+ printf "\n%s%s%s\n\n" "$bold" "$1" "$normal"
28+
29+ echo -e "\n### $1\n" >> "$REPORT"
30+}
31+
32+RESULT_DIR="benchmark-results"
33+REPORT="$RESULT_DIR/report.md"
34+
22TARGET_DIR="$(get_cargo_target_dir)"
35TARGET_DIR="$(get_cargo_target_dir)"
23−TARGET_DEBUG="${TARGET_DIR}/debug/bat"
24TARGET_RELEASE="${TARGET_DIR}/release/bat"
36TARGET_RELEASE="${TARGET_DIR}/release/bat"
25
37
38+WARMUP_COUNT=3
39+
26# Determine which target to benchmark.
40# Determine which target to benchmark.
27BAT=''
41BAT=''
28for arg in "$@"; do
42for arg in "$@"; do
29 case "$arg" in
43 case "$arg" in
30 --system) BAT="bat" ;;
44 --system) BAT="bat" ;;
31− --debug) BAT="$TARGET_DEBUG" ;;
32 --release) BAT="$TARGET_RELEASE" ;;
45 --release) BAT="$TARGET_RELEASE" ;;
33 --bat=*) BAT="${arg:6}" ;;
46 --bat=*) BAT="${arg:6}" ;;
34 esac
47 esac
@@ -36,37 +49,48 @@ done
36
49
37if [[ -z "$BAT" ]]; then
50if [[ -z "$BAT" ]]; then
38 echo "A build of 'bat' must be specified for benchmarking."
51 echo "A build of 'bat' must be specified for benchmarking."
39− echo "You can use '--system', '--debug', or '--release'."
52+ echo "You can use '--system', '--release' or '--bat=path/to/bat'."
40 exit 1
53 exit 1
41fi
54fi
42
55
43−# Ensure that the target is built.
44if ! command -v "$BAT" &>/dev/null; then
56if ! command -v "$BAT" &>/dev/null; then
45− echo "Could not find the build of bat to benchmark."
57+ echo "Could not find the build of bat to benchmark ($BAT)."
46 case "$BAT" in
58 case "$BAT" in
47 "bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
59 "bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
48− "$TARGET_DEBUG") echo "Make you sure to 'cargo build' first." ;;
49 "$TARGET_RELEASE") echo "Make you sure to 'cargo build --release' first." ;;
60 "$TARGET_RELEASE") echo "Make you sure to 'cargo build --release' first." ;;
50 esac
61 esac
51 exit 1
62 exit 1
52fi
63fi
53
64
54−# Run the benchmark.
65+# Run the benchmarks
55−echo "### Startup time"
66+mkdir -p "$RESULT_DIR"
56−echo
67+rm -f "$RESULT_DIR"/*.md
57
68
58−hyperfine --warmup 3 "$BAT"
69+echo "## \`bat\` benchmark results" >> "$REPORT"
59
70
60−echo
71+heading "Startup time"
61−echo "### Plain text"
72+hyperfine \
62−echo
73+ "$BAT" \
74+ --warmup "$WARMUP_COUNT" \
75+ --export-markdown "$RESULT_DIR/startup-time.md" \
76+ --export-json "$RESULT_DIR/startup-time.json"
77+cat "$RESULT_DIR/startup-time.md" >> "$REPORT"
63
78
79+heading "Plain text speed"
80+hyperfine \
64−hyperfine --warmup 3 "$(printf "%q" "$BAT") --language txt --paging=never 'test-src/jquery-3.3.1.js'"
81+ "$(printf "%q" "$BAT") --language txt --paging=never 'test-src/jquery-3.3.1.js'" \
65−
82+ --warmup "$WARMUP_COUNT" \
66−echo
83+ --export-markdown "$RESULT_DIR/plain-text-speed.md" \
67−echo "### Time to syntax-highlight large files"
84+ --export-json "$RESULT_DIR/plain-text-speed.json"
68−echo
85+cat "$RESULT_DIR/plain-text-speed.md" >> "$REPORT"
69
86
70for SRC in test-src/*; do
87for SRC in test-src/*; do
88+ filename="$(basename "$SRC")"
89+ heading "Syntax highlighting speed: \`$filename\`"
90+
91+ hyperfine --warmup "$WARMUP_COUNT" \
71− hyperfine --warmup 3 "$(printf "%q" "$BAT") --style=full --color=always --paging=never $(printf "%q" "$SRC")"
92+ "$(printf "%q" "$BAT") --style=full --color=always --paging=never $(printf "%q" "$SRC")" \
93+ --export-markdown "$RESULT_DIR/syntax-highlighting-speed-${filename}.md" \
94+ --export-json "$RESULT_DIR/syntax-highlighting-speed-${filename}.json"
95+ cat "$RESULT_DIR/syntax-highlighting-speed-${filename}.md" >> "$REPORT"
72done
96done