2020-10-04 09:37:37 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-11-22 20:06:48 +00:00
|
|
|
|
2020-11-29 22:41:18 +00:00
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
|
2020-10-04 10:07:22 +00:00
|
|
|
|
2020-12-29 23:07:22 +00:00
|
|
|
# Check that Hyperfine is installed.
|
2020-11-29 22:41:18 +00:00
|
|
|
if ! command -v hyperfine > /dev/null 2>&1; then
|
2021-08-21 10:25:26 +00: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 19:42:07 +00:00
|
|
|
fi
|
|
|
|
|
2021-11-22 19:49:10 +00: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://stedolan.github.io/jq"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-08-21 10:25:26 +00:00
|
|
|
|
2021-11-22 19:49:10 +00:00
|
|
|
get_cargo_target_dir() {
|
|
|
|
cargo metadata --no-deps --format-version 1 | jq -r .target_directory
|
2020-12-29 23:07:22 +00:00
|
|
|
}
|
|
|
|
|
2021-11-22 20:06:48 +00: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 20:52:28 +00: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 20:06:48 +00:00
|
|
|
RESULT_DIR="benchmark-results"
|
|
|
|
REPORT="$RESULT_DIR/report.md"
|
|
|
|
|
2021-11-22 19:49:10 +00:00
|
|
|
TARGET_DIR="$(get_cargo_target_dir)"
|
2020-12-29 23:07:22 +00:00
|
|
|
TARGET_RELEASE="${TARGET_DIR}/release/bat"
|
|
|
|
|
2021-11-22 20:06:48 +00:00
|
|
|
WARMUP_COUNT=3
|
|
|
|
|
2020-12-29 23:07:22 +00:00
|
|
|
# Determine which target to benchmark.
|
2020-10-05 22:28:23 +00:00
|
|
|
BAT=''
|
|
|
|
for arg in "$@"; do
|
|
|
|
case "$arg" in
|
|
|
|
--system) BAT="bat" ;;
|
2020-12-29 23:07:22 +00:00
|
|
|
--release) BAT="$TARGET_RELEASE" ;;
|
2020-10-05 22:42:00 +00:00
|
|
|
--bat=*) BAT="${arg:6}" ;;
|
2020-10-05 22:28:23 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -z "$BAT" ]]; then
|
|
|
|
echo "A build of 'bat' must be specified for benchmarking."
|
2021-11-22 20:06:48 +00:00
|
|
|
echo "You can use '--system', '--release' or '--bat=path/to/bat'."
|
2020-10-05 22:28:23 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! command -v "$BAT" &>/dev/null; then
|
2021-11-22 20:06:48 +00:00
|
|
|
echo "Could not find the build of bat to benchmark ($BAT)."
|
2020-10-05 22:28:23 +00:00
|
|
|
case "$BAT" in
|
2020-12-29 23:07:22 +00:00
|
|
|
"bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
|
|
|
|
"$TARGET_RELEASE") echo "Make you sure to 'cargo build --release' first." ;;
|
2020-10-05 22:28:23 +00:00
|
|
|
esac
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-11-22 20:06:48 +00:00
|
|
|
# Run the benchmarks
|
|
|
|
mkdir -p "$RESULT_DIR"
|
|
|
|
rm -f "$RESULT_DIR"/*.md
|
2018-05-14 19:42:07 +00:00
|
|
|
|
2021-11-22 20:06:48 +00:00
|
|
|
echo "## \`bat\` benchmark results" >> "$REPORT"
|
2018-05-14 19:42:07 +00:00
|
|
|
|
2021-11-22 20:52:28 +00:00
|
|
|
|
2021-11-22 20:06:48 +00:00
|
|
|
heading "Startup time"
|
|
|
|
hyperfine \
|
2021-11-22 20:52:28 +00:00
|
|
|
"$(printf "%q" "$BAT") --no-config" \
|
|
|
|
--command-name "bat" \
|
2021-11-22 20:06:48 +00:00
|
|
|
--warmup "$WARMUP_COUNT" \
|
|
|
|
--export-markdown "$RESULT_DIR/startup-time.md" \
|
|
|
|
--export-json "$RESULT_DIR/startup-time.json"
|
|
|
|
cat "$RESULT_DIR/startup-time.md" >> "$REPORT"
|
2018-05-14 19:42:07 +00:00
|
|
|
|
2021-11-22 20:52:28 +00:00
|
|
|
|
2021-11-25 20:20:38 +00:00
|
|
|
heading "Startup time with syntax highlighting"
|
|
|
|
hyperfine \
|
2021-11-26 19:58:33 +00:00
|
|
|
"$(printf "%q" "$BAT") --no-config --color=always test-src/small-CpuInfo-file.cpuinfo" \
|
|
|
|
--command-name "bat … small-CpuInfo-file.cpuinfo" \
|
2021-11-25 20:20:38 +00:00
|
|
|
--warmup "$WARMUP_COUNT" \
|
|
|
|
--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 19:58:33 +00:00
|
|
|
heading "Startup time with syntax with dependencies"
|
|
|
|
hyperfine \
|
|
|
|
"$(printf "%q" "$BAT") --no-config --color=always test-src/small-Markdown-file.md" \
|
|
|
|
--command-name "bat … small-Markdown-file.md" \
|
|
|
|
--warmup "$WARMUP_COUNT" \
|
|
|
|
--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"
|
|
|
|
|
|
|
|
|
2021-11-22 20:52:28 +00:00
|
|
|
heading "Plain-text speed"
|
2021-11-22 20:06:48 +00:00
|
|
|
hyperfine \
|
2021-11-22 20:54:04 +00:00
|
|
|
"$(printf "%q" "$BAT") --no-config --language=txt --style=plain test-src/numpy_test_multiarray.py" \
|
|
|
|
--command-name 'bat … --language=txt numpy_test_multiarray.py' \
|
2021-11-22 20:06:48 +00:00
|
|
|
--warmup "$WARMUP_COUNT" \
|
|
|
|
--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 19:42:07 +00:00
|
|
|
|
2021-11-22 20:52:28 +00:00
|
|
|
|
2018-05-14 19:42:07 +00:00
|
|
|
for SRC in test-src/*; do
|
2021-11-22 20:06:48 +00:00
|
|
|
filename="$(basename "$SRC")"
|
|
|
|
|
2021-11-22 20:52:28 +00:00
|
|
|
heading "Syntax highlighting speed: \`$filename\`"
|
2021-11-22 20:06:48 +00:00
|
|
|
hyperfine --warmup "$WARMUP_COUNT" \
|
2021-11-22 20:52:28 +00:00
|
|
|
"$(printf "%q" "$BAT") --no-config --style=full --color=always --wrap=character --terminal-width=80 '$SRC'" \
|
|
|
|
--command-name "bat … ${filename}" \
|
2021-11-22 20:06:48 +00:00
|
|
|
--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"
|
2018-05-14 19:42:07 +00:00
|
|
|
done
|