2020-10-04 11:37:37 +02:00
|
|
|
#!/usr/bin/env bash
|
2021-11-22 21:06:48 +01:00
|
|
|
|
2020-11-29 23:41:18 +01:00
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
|
2020-10-04 12:07:22 +02:00
|
|
|
|
2020-12-30 00:07:22 +01:00
|
|
|
# Check that Hyperfine is installed.
|
2020-11-29 23:41:18 +01:00
|
|
|
if ! command -v hyperfine > /dev/null 2>&1; then
|
2021-08-21 12:25:26 +02:00
|
|
|
echo "'hyperfine' does not seem to be installed."
|
|
|
|
echo "You can get it here: https://github.com/sharkdp/hyperfine"
|
|
|
|
exit 1
|
2018-05-14 21:42:07 +02:00
|
|
|
fi
|
|
|
|
|
2023-12-11 03:38:59 +01:00
|
|
|
# Check that jq is installed.
|
|
|
|
if ! command -v jq > /dev/null 2>&1; then
|
|
|
|
echo "'jq' does not seem to be installed."
|
|
|
|
echo "You can get it here: https://jqlang.github.io/jq/download/"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-02-02 21:02:31 +01:00
|
|
|
# Check that python3 is installed.
|
|
|
|
if ! command -v python3 > /dev/null 2>&1; then
|
|
|
|
echo "'python3' does not seem to be installed."
|
|
|
|
echo "You can get it here: https://www.python.org/downloads/"
|
2021-11-22 20:49:10 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-08-21 12:25:26 +02:00
|
|
|
|
2021-11-22 20:49:10 +01:00
|
|
|
get_cargo_target_dir() {
|
2022-02-02 21:02:31 +01:00
|
|
|
cargo metadata --no-deps --format-version 1 | python3 -c 'import sys, json; print(json.load(sys.stdin)["target_directory"])'
|
2020-12-30 00:07:22 +01:00
|
|
|
}
|
|
|
|
|
2021-11-22 21:06:48 +01:00
|
|
|
heading() {
|
|
|
|
bold=$(tput bold)$(tput setaf 220)
|
|
|
|
normal=$(tput sgr0)
|
|
|
|
echo
|
|
|
|
printf "\n%s%s%s\n\n" "$bold" "$1" "$normal"
|
|
|
|
|
|
|
|
echo -e "\n### $1\n" >> "$REPORT"
|
|
|
|
}
|
|
|
|
|
2021-11-22 21:52:28 +01:00
|
|
|
# Clean up environment
|
|
|
|
unset BAT_CACHE_PATH
|
|
|
|
unset BAT_CONFIG_DIR
|
|
|
|
unset BAT_CONFIG_PATH
|
|
|
|
unset BAT_OPTS
|
|
|
|
unset BAT_PAGER
|
|
|
|
unset BAT_STYLE
|
|
|
|
unset BAT_TABS
|
|
|
|
unset BAT_THEME
|
|
|
|
unset COLORTERM
|
|
|
|
unset NO_COLOR
|
|
|
|
unset PAGER
|
|
|
|
|
|
|
|
|
2021-11-22 21:06:48 +01:00
|
|
|
RESULT_DIR="benchmark-results"
|
|
|
|
REPORT="$RESULT_DIR/report.md"
|
|
|
|
|
2021-11-22 20:49:10 +01:00
|
|
|
TARGET_DIR="$(get_cargo_target_dir)"
|
2020-12-30 00:07:22 +01:00
|
|
|
TARGET_RELEASE="${TARGET_DIR}/release/bat"
|
|
|
|
|
2023-11-05 13:19:10 +01:00
|
|
|
: ${WARMUP_COUNT:=3}
|
|
|
|
: ${RUN_COUNT:=10}
|
2021-11-22 21:06:48 +01:00
|
|
|
|
2020-12-30 00:07:22 +01:00
|
|
|
# Determine which target to benchmark.
|
2020-10-06 00:28:23 +02:00
|
|
|
BAT=''
|
|
|
|
for arg in "$@"; do
|
|
|
|
case "$arg" in
|
|
|
|
--system) BAT="bat" ;;
|
2020-12-30 00:07:22 +01:00
|
|
|
--release) BAT="$TARGET_RELEASE" ;;
|
2020-10-06 00:42:00 +02:00
|
|
|
--bat=*) BAT="${arg:6}" ;;
|
2020-10-06 00:28:23 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -z "$BAT" ]]; then
|
|
|
|
echo "A build of 'bat' must be specified for benchmarking."
|
2021-11-22 21:06:48 +01:00
|
|
|
echo "You can use '--system', '--release' or '--bat=path/to/bat'."
|
2020-10-06 00:28:23 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! command -v "$BAT" &>/dev/null; then
|
2021-11-22 21:06:48 +01:00
|
|
|
echo "Could not find the build of bat to benchmark ($BAT)."
|
2020-10-06 00:28:23 +02:00
|
|
|
case "$BAT" in
|
2020-12-30 00:07:22 +01:00
|
|
|
"bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
|
|
|
|
"$TARGET_RELEASE") echo "Make you sure to 'cargo build --release' first." ;;
|
2020-10-06 00:28:23 +02:00
|
|
|
esac
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-11-22 21:06:48 +01:00
|
|
|
# Run the benchmarks
|
|
|
|
mkdir -p "$RESULT_DIR"
|
|
|
|
rm -f "$RESULT_DIR"/*.md
|
2018-05-14 21:42:07 +02:00
|
|
|
|
2021-11-22 21:06:48 +01:00
|
|
|
echo "## \`bat\` benchmark results" >> "$REPORT"
|
2018-05-14 21:42:07 +02:00
|
|
|
|
2021-11-22 21:52:28 +01:00
|
|
|
|
2021-11-22 21:06:48 +01:00
|
|
|
heading "Startup time"
|
|
|
|
hyperfine \
|
2021-11-22 21:52:28 +01:00
|
|
|
"$(printf "%q" "$BAT") --no-config" \
|
|
|
|
--command-name "bat" \
|
2021-11-22 21:06:48 +01:00
|
|
|
--warmup "$WARMUP_COUNT" \
|
2023-11-05 13:15:51 +01:00
|
|
|
--runs "$RUN_COUNT" \
|
2021-11-22 21:06:48 +01:00
|
|
|
--export-markdown "$RESULT_DIR/startup-time.md" \
|
|
|
|
--export-json "$RESULT_DIR/startup-time.json"
|
|
|
|
cat "$RESULT_DIR/startup-time.md" >> "$REPORT"
|
2018-05-14 21:42:07 +02:00
|
|
|
|
2021-11-22 21:52:28 +01:00
|
|
|
|
2021-11-25 21:20:38 +01:00
|
|
|
heading "Startup time with syntax highlighting"
|
|
|
|
hyperfine \
|
2021-12-08 11:31:54 +01:00
|
|
|
"$(printf "%q" "$BAT") --no-config --color=always startup-time-src/small-CpuInfo-file.cpuinfo" \
|
2021-11-26 20:58:33 +01:00
|
|
|
--command-name "bat … small-CpuInfo-file.cpuinfo" \
|
2021-11-25 21:20:38 +01:00
|
|
|
--warmup "$WARMUP_COUNT" \
|
2023-11-05 13:15:51 +01:00
|
|
|
--runs "$RUN_COUNT" \
|
2021-11-25 21:20:38 +01:00
|
|
|
--export-markdown "$RESULT_DIR/startup-time-with-syntax-highlighting.md" \
|
|
|
|
--export-json "$RESULT_DIR/startup-time-with-syntax-highlighting.json"
|
|
|
|
cat "$RESULT_DIR/startup-time-with-syntax-highlighting.md" >> "$REPORT"
|
|
|
|
|
|
|
|
|
2021-11-26 20:58:33 +01:00
|
|
|
heading "Startup time with syntax with dependencies"
|
|
|
|
hyperfine \
|
2021-12-08 11:31:54 +01:00
|
|
|
"$(printf "%q" "$BAT") --no-config --color=always startup-time-src/small-Markdown-file.md" \
|
2021-11-26 20:58:33 +01:00
|
|
|
--command-name "bat … small-Markdown-file.md" \
|
|
|
|
--warmup "$WARMUP_COUNT" \
|
2023-11-05 13:15:51 +01:00
|
|
|
--runs "$RUN_COUNT" \
|
2021-11-26 20:58:33 +01:00
|
|
|
--export-markdown "$RESULT_DIR/startup-time-with-syntax-with-dependencies.md" \
|
|
|
|
--export-json "$RESULT_DIR/startup-time-with-syntax-with-dependencies.json"
|
|
|
|
cat "$RESULT_DIR/startup-time-with-syntax-with-dependencies.md" >> "$REPORT"
|
|
|
|
|
|
|
|
|
2023-12-11 03:38:59 +01:00
|
|
|
heading "Startup time with indeterminant syntax"
|
|
|
|
hyperfine \
|
|
|
|
"$(printf "%q" "$BAT") --no-config startup-time-src/mystery-file" \
|
|
|
|
--command-name 'bat … mystery-file' \
|
|
|
|
--warmup "$WARMUP_COUNT" \
|
|
|
|
--runs $(($RUN_COUNT * 100)) \
|
|
|
|
--export-markdown "$RESULT_DIR/startup-time-with-indeterminant-syntax.md" \
|
|
|
|
--export-json "$RESULT_DIR/startup-time-with-indeterminant-syntax.json"
|
|
|
|
cat "$RESULT_DIR/startup-time-with-indeterminant-syntax.md" >> "$REPORT"
|
|
|
|
|
|
|
|
heading "Startup time with manually set syntax"
|
|
|
|
hyperfine \
|
|
|
|
"$(printf "%q" "$BAT") --no-config --language=Dockerfile startup-time-src/mystery-file" \
|
|
|
|
--command-name 'bat … --language=Dockerfile mystery-file' \
|
|
|
|
--warmup "$WARMUP_COUNT" \
|
|
|
|
--runs $(($RUN_COUNT * 100)) \
|
|
|
|
--export-markdown "$RESULT_DIR/startup-time-with-manually-set-syntax.md" \
|
|
|
|
--export-json "$RESULT_DIR/startup-time-with-manually-set-syntax.json"
|
|
|
|
cat "$RESULT_DIR/startup-time-with-manually-set-syntax.md" >> "$REPORT"
|
|
|
|
|
|
|
|
heading "Startup time with mapped syntax"
|
|
|
|
hyperfine \
|
|
|
|
"$(printf "%q" "$BAT") --no-config startup-time-src/Containerfile" \
|
|
|
|
--command-name 'bat … Containerfile' \
|
|
|
|
--warmup "$WARMUP_COUNT" \
|
|
|
|
--runs $(($RUN_COUNT * 100)) \
|
|
|
|
--export-markdown "$RESULT_DIR/startup-time-with-mapped-syntax.md" \
|
|
|
|
--export-json "$RESULT_DIR/startup-time-with-mapped-syntax.json"
|
|
|
|
cat "$RESULT_DIR/startup-time-with-mapped-syntax.md" >> "$REPORT"
|
|
|
|
|
|
|
|
AVG_TIMES=()
|
|
|
|
for KIND in indeterminant manually-set mapped; do
|
|
|
|
JSON_SRC="$RESULT_DIR/startup-time-with-$KIND-syntax.json"
|
|
|
|
AVG=$(jq -r '.results[0].mean' "$JSON_SRC")
|
|
|
|
AVG_TIMES+=("$AVG")
|
|
|
|
done
|
|
|
|
# indeterminant should be slower, because it necessarily has to evaluate all rules
|
|
|
|
# to ensure that nothing matches; manually-set and mapped should both be faster
|
|
|
|
# because most or all GlobMatcher builds are skipped
|
|
|
|
python3 -c "if ${AVG_TIMES[0]} < ${AVG_TIMES[1]}: print('WARN: indeterminant syntax has faster startup than manually set syntax!')"
|
|
|
|
python3 -c "if ${AVG_TIMES[0]} < ${AVG_TIMES[2]}: print('WARN: indeterminant syntax has faster startup than mapped syntax!')"
|
|
|
|
|
|
|
|
|
2021-11-22 21:52:28 +01:00
|
|
|
heading "Plain-text speed"
|
2021-11-22 21:06:48 +01:00
|
|
|
hyperfine \
|
2021-12-08 11:31:54 +01:00
|
|
|
"$(printf "%q" "$BAT") --no-config --language=txt --style=plain highlighting-speed-src/numpy_test_multiarray.py" \
|
2021-11-22 21:54:04 +01:00
|
|
|
--command-name 'bat … --language=txt numpy_test_multiarray.py' \
|
2021-11-22 21:06:48 +01:00
|
|
|
--warmup "$WARMUP_COUNT" \
|
2023-11-05 13:15:51 +01:00
|
|
|
--runs "$RUN_COUNT" \
|
2021-11-22 21:06:48 +01:00
|
|
|
--export-markdown "$RESULT_DIR/plain-text-speed.md" \
|
|
|
|
--export-json "$RESULT_DIR/plain-text-speed.json"
|
|
|
|
cat "$RESULT_DIR/plain-text-speed.md" >> "$REPORT"
|
2018-05-14 21:42:07 +02:00
|
|
|
|
2021-11-22 21:52:28 +01:00
|
|
|
|
2021-12-08 12:03:59 +01:00
|
|
|
for wrap in character never; do
|
|
|
|
for SRC in highlighting-speed-src/*; do
|
|
|
|
filename="$(basename "$SRC")"
|
|
|
|
|
|
|
|
heading "Syntax highlighting speed --wrap=${wrap}: \`$filename\`"
|
|
|
|
hyperfine --warmup "$WARMUP_COUNT" \
|
2023-11-05 13:15:51 +01:00
|
|
|
--runs "$RUN_COUNT" \
|
2021-12-08 12:03:59 +01:00
|
|
|
"$(printf "%q" "$BAT") --no-config --style=full --color=always --wrap=${wrap} --terminal-width=80 '$SRC'" \
|
|
|
|
--command-name "bat … ${filename}" \
|
|
|
|
--export-markdown "$RESULT_DIR/syntax-highlighting-speed-${filename}.md" \
|
|
|
|
--export-json "$RESULT_DIR/syntax-highlighting-speed-${filename}.json"
|
|
|
|
cat "$RESULT_DIR/syntax-highlighting-speed-${filename}.md" >> "$REPORT"
|
|
|
|
done
|
2018-05-14 21:42:07 +02:00
|
|
|
done
|
2022-02-07 20:48:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
heading "Many small files speed (overhead of metadata)"
|
|
|
|
hyperfine \
|
|
|
|
"$(printf "%q" "$BAT") --no-config --language=txt --style=plain many-small-files/*.txt" \
|
|
|
|
--command-name 'bat … --language=txt *.txt' \
|
|
|
|
--warmup "$WARMUP_COUNT" \
|
2023-11-05 13:15:51 +01:00
|
|
|
--runs "$RUN_COUNT" \
|
2022-02-07 20:48:57 +01:00
|
|
|
--export-markdown "$RESULT_DIR/many-small-files-speed.md" \
|
|
|
|
--export-json "$RESULT_DIR/many-small-files-speed.json"
|
|
|
|
cat "$RESULT_DIR/many-small-files-speed.md" >> "$REPORT"
|