mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-19 12:24:17 +00:00
Merge pull request #1268 from eth-p/improved-benchmark
Add option to specify bat target in run-benchmarks.sh
This commit is contained in:
commit
4fe5497d19
52
tests/benchmarks/run-benchmarks.sh
vendored
52
tests/benchmarks/run-benchmarks.sh
vendored
@ -1,28 +1,72 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
|
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
|
||||||
|
|
||||||
|
# Check that Hyperfine is installed.
|
||||||
if ! command -v hyperfine > /dev/null 2>&1; then
|
if ! command -v hyperfine > /dev/null 2>&1; then
|
||||||
echo "'hyperfine' does not seem to be installed."
|
echo "'hyperfine' does not seem to be installed."
|
||||||
echo "You can get it here: https://github.com/sharkdp/hyperfine"
|
echo "You can get it here: https://github.com/sharkdp/hyperfine"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
echo "../../target"
|
||||||
|
}
|
||||||
|
|
||||||
|
TARGET_DIR="$(get_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.
|
||||||
echo "### Startup time"
|
echo "### Startup time"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
hyperfine --warmup 3 bat
|
hyperfine --warmup 3 "$BAT"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "### Plain text"
|
echo "### Plain text"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
hyperfine --warmup 3 "bat --language txt --paging=never 'test-src/jquery-3.3.1.js'"
|
hyperfine --warmup 3 "$(printf "%q" "$BAT") --language txt --paging=never 'test-src/jquery-3.3.1.js'"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "### Time to syntax-highlight large files"
|
echo "### Time to syntax-highlight large files"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
for SRC in test-src/*; do
|
for SRC in test-src/*; do
|
||||||
hyperfine --warmup 3 "bat --style=full --color=always --paging=never '$SRC'"
|
hyperfine --warmup 3 "$(printf "%q" "$BAT") --style=full --color=always --paging=never $(printf "%q" "$SRC")"
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user