@@ -1,18 +1,35 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2cd "$(dirname "${BASH_SOURCE[0]}")"
2cd "$(dirname "${BASH_SOURCE[0]}")"
4+# Check that Hyperfine is installed.
4if ! which hyperfine > /dev/null 2>&1; then
5if ! which hyperfine > /dev/null 2>&1; then
5− echo "'hyperfine' does not seem to be installed."
6+ echo "'hyperfine' does not seem to be installed." 1>&2
6− echo "You can get it here: https://github.com/sharkdp/hyperfine"
7+ echo "You can get it here: https://github.com/sharkdp/hyperfine" 1>&2
11+# Determine the target directories.
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:]]*$//' \
22+TARGET_DIR="$(get_target_dir)"
23+TARGET_DEBUG="${TARGET_DIR}/debug/bat"
24+TARGET_RELEASE="${TARGET_DIR}/release/bat"
26+# Determine which target to benchmark.
11for arg in "$@"; do
28for arg in "$@"; do
12 case "$arg" in
29 case "$arg" in
13 --system) BAT="bat" ;;
30 --system) BAT="bat" ;;
14− --debug) BAT="../../target/debug/bat" ;;
31+ --debug) BAT="$TARGET_DEBUG" ;;
15− --release) BAT="../../target/release/bat" ;;
32+ --release) BAT="$TARGET_RELEASE" ;;
16 --bat=*) BAT="${arg:6}" ;;
33 --bat=*) BAT="${arg:6}" ;;
@@ -23,16 +40,18 @@ if [[ -z "$BAT" ]]; then
43+# Ensure that the target is built.
26if ! command -v "$BAT" &>/dev/null; then
44if ! command -v "$BAT" &>/dev/null; then
27 echo "Could not find the build of bat to benchmark."
45 echo "Could not find the build of bat to benchmark."
28 case "$BAT" in
46 case "$BAT" in
29− "bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
47+ "bat") echo "Make you sure to symlink 'batcat' as 'bat'." ;;
30− "../../target/debug/debug") echo "Make you sure to 'cargo build' first." ;;
48+ "$TARGET_DEBUG") echo "Make you sure to 'cargo build' first." ;;
31− "../../target/debug/release") echo "Make you sure to 'cargo build --release' first." ;;
49+ "$TARGET_RELEASE") echo "Make you sure to 'cargo build --release' first." ;;
36echo "### Startup time"
55echo "### Startup time"