2020-10-04 11:37:37 +02:00
|
|
|
#!/usr/bin/env bash
|
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
|
|
|
|
|
2020-12-30 00:07:22 +01:00
|
|
|
# Determine the target directories.
|
|
|
|
get_target_dir() {
|
|
|
|
if [[ -f "$HOME/.cargo/config" ]]; then
|
|
|
|
grep 'target-dir[[:space:]]*=' "$HOME/.cargo/config" \
|
|
|
|
| sed 's/^[[:space:]]*target-dir[[:space:]]*=//; s/^[[:space:]]*"//; s/"[[:space:]]*$//' \
|
|
|
|
&& return 0
|
|
|
|
fi
|
2021-08-21 12:25:26 +02:00
|
|
|
|
2020-12-30 00:07:22 +01:00
|
|
|
echo "../../target"
|
|
|
|
}
|
|
|
|
|
|
|
|
TARGET_DIR="$(get_target_dir)"
|
|
|
|
TARGET_DEBUG="${TARGET_DIR}/debug/bat"
|
|
|
|
TARGET_RELEASE="${TARGET_DIR}/release/bat"
|
|
|
|
|
|
|
|
# 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
|
|
|
--debug) BAT="$TARGET_DEBUG" ;;
|
|
|
|
--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."
|
|
|
|
echo "You can use '--system', '--debug', or '--release'."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-12-30 00:07:22 +01:00
|
|
|
# Ensure that the target is built.
|
2020-10-06 00:28:23 +02:00
|
|
|
if ! command -v "$BAT" &>/dev/null; then
|
|
|
|
echo "Could not find the build of bat to benchmark."
|
|
|
|
case "$BAT" in
|
2020-12-30 00:07:22 +01:00
|
|
|
"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." ;;
|
2020-10-06 00:28:23 +02:00
|
|
|
esac
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-12-30 00:07:22 +01:00
|
|
|
# Run the benchmark.
|
2018-05-14 21:42:07 +02:00
|
|
|
echo "### Startup time"
|
|
|
|
echo
|
|
|
|
|
2020-10-06 00:28:23 +02:00
|
|
|
hyperfine --warmup 3 "$BAT"
|
2018-05-14 21:42:07 +02:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "### Plain text"
|
|
|
|
echo
|
|
|
|
|
2020-10-06 00:28:23 +02:00
|
|
|
hyperfine --warmup 3 "$(printf "%q" "$BAT") --language txt --paging=never 'test-src/jquery-3.3.1.js'"
|
2018-05-14 21:42:07 +02:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "### Time to syntax-highlight large files"
|
|
|
|
echo
|
|
|
|
|
|
|
|
for SRC in test-src/*; do
|
2021-08-21 12:25:26 +02:00
|
|
|
hyperfine --warmup 3 "$(printf "%q" "$BAT") --style=full --color=always --paging=never $(printf "%q" "$SRC")"
|
2018-05-14 21:42:07 +02:00
|
|
|
done
|