bat/tests/benchmarks/run-benchmarks.sh

73 lines
1.8 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
# Check that Hyperfine is installed.
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
}
2021-11-22 19:49:10 +00:00
TARGET_DIR="$(get_cargo_target_dir)"
TARGET_DEBUG="${TARGET_DIR}/debug/bat"
TARGET_RELEASE="${TARGET_DIR}/release/bat"
# Determine which target to benchmark.
BAT=''
for arg in "$@"; do
case "$arg" in
--system) BAT="bat" ;;
--debug) BAT="$TARGET_DEBUG" ;;
--release) BAT="$TARGET_RELEASE" ;;
--bat=*) BAT="${arg:6}" ;;
esac
done
if [[ -z "$BAT" ]]; then
echo "A build of 'bat' must be specified for benchmarking."
echo "You can use '--system', '--debug', or '--release'."
exit 1
fi
# Ensure that the target is built.
if ! command -v "$BAT" &>/dev/null; then
echo "Could not find the build of bat to benchmark."
case "$BAT" in
"bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
"$TARGET_DEBUG") echo "Make you sure to 'cargo build' first." ;;
"$TARGET_RELEASE") echo "Make you sure to 'cargo build --release' first." ;;
esac
exit 1
fi
# Run the benchmark.
2018-05-14 19:42:07 +00:00
echo "### Startup time"
echo
hyperfine --warmup 3 "$BAT"
2018-05-14 19:42:07 +00:00
echo
echo "### Plain text"
echo
hyperfine --warmup 3 "$(printf "%q" "$BAT") --language txt --paging=never 'test-src/jquery-3.3.1.js'"
2018-05-14 19:42:07 +00:00
echo
echo "### Time to syntax-highlight large files"
echo
for SRC in test-src/*; do
2021-08-21 10:25:26 +00:00
hyperfine --warmup 3 "$(printf "%q" "$BAT") --style=full --color=always --paging=never $(printf "%q" "$SRC")"
2018-05-14 19:42:07 +00:00
done