@@ -1,18 +1,35 @@
11#!/usr/bin/env bash
22cd "$(dirname "${BASH_SOURCE[0]}")"
33
4+# Check that Hyperfine is installed.
45if ! which hyperfine > /dev/null 2>&1; then
5− echo "'hyperfine' does not seem to be installed."
6− echo "You can get it here: https://github.com/sharkdp/hyperfine"
6+ echo "'hyperfine' does not seem to be installed." 1>&2
7+ echo "You can get it here: https://github.com/sharkdp/hyperfine" 1>&2
78 exit 1
89fi
910
11+# Determine the target directories.
12+get_target_dir() {
13+ if [[ -f "$HOME/.cargo/config" ]]; then
14+ grep 'target-dir[[:space:]]*=' "$HOME/.cargo/config" \
15+ | sed 's/^[[:space:]]*target-dir[[:space:]]*=//; s/^[[:space:]]*"//; s/"[[:space:]]*$//' \
16+ && return 0
17+ fi
18+
19+ echo "../../target"
20+}
21+
22+TARGET_DIR="$(get_target_dir)"
23+TARGET_DEBUG="${TARGET_DIR}/debug/bat"
24+TARGET_RELEASE="${TARGET_DIR}/release/bat"
25+
26+# Determine which target to benchmark.
1027BAT=''
1128for arg in "$@"; do
1229 case "$arg" in
1330 --system) BAT="bat" ;;
14− --debug) BAT="../../target/debug/bat" ;;
15− --release) BAT="../../target/release/bat" ;;
31+ --debug) BAT="$TARGET_DEBUG" ;;
32+ --release) BAT="$TARGET_RELEASE" ;;
1633 --bat=*) BAT="${arg:6}" ;;
1734 esac
1835done
@@ -23,16 +40,18 @@ if [[ -z "$BAT" ]]; then
2340 exit 1
2441fi
2542
43+# Ensure that the target is built.
2644if ! command -v "$BAT" &>/dev/null; then
2745 echo "Could not find the build of bat to benchmark."
2846 case "$BAT" in
29− "bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
30− "../../target/debug/debug") echo "Make you sure to 'cargo build' first." ;;
31− "../../target/debug/release") echo "Make you sure to 'cargo build --release' first." ;;
47+ "bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
48+ "$TARGET_DEBUG") echo "Make you sure to 'cargo build' first." ;;
49+ "$TARGET_RELEASE") echo "Make you sure to 'cargo build --release' first." ;;
3250 esac
3351 exit 1
3452fi
3553
54+# Run the benchmark.
3655echo "### Startup time"
3756echo
3857