on master help sign in
Improve benchmark script to support cargo/config target-dir
3ed0081Ethan P
tests/benchmarks/run-benchmarks.sh+26−7
@@ -1,18 +1,35 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2cd "$(dirname "${BASH_SOURCE[0]}")"
2cd "$(dirname "${BASH_SOURCE[0]}")"
3
3
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
7 exit 1
8 exit 1
8fi
9fi
9
10
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.
10BAT=''
27BAT=''
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}" ;;
17 esac
34 esac
18done
35done
@@ -23,16 +40,18 @@ if [[ -z "$BAT" ]]; then
23 exit 1
40 exit 1
24fi
41fi
25
42
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." ;;
32 esac
50 esac
33 exit 1
51 exit 1
34fi
52fi
35
53
54+# Run the benchmark.
36echo "### Startup time"
55echo "### Startup time"
37echo
56echo
38
57