From e3bc41dbe67c964c1d35ab1c127b28991ae19772 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Mon, 5 Oct 2020 15:28:23 -0700 Subject: [PATCH 1/3] Add option to specify bat target in run-benchmarks.sh --- tests/benchmarks/run-benchmarks.sh | 32 ++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/benchmarks/run-benchmarks.sh b/tests/benchmarks/run-benchmarks.sh index c3a15509..3e0da33d 100755 --- a/tests/benchmarks/run-benchmarks.sh +++ b/tests/benchmarks/run-benchmarks.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash - cd "$(dirname "${BASH_SOURCE[0]}")" if ! which hyperfine > /dev/null 2>&1; then @@ -8,21 +7,46 @@ if ! which hyperfine > /dev/null 2>&1; then exit 1 fi +BAT='' +for arg in "$@"; do + case "$arg" in + --system) BAT="bat" ;; + --debug) BAT="../../target/debug/bat" ;; + --release) BAT="../../target/release/bat" ;; + 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 + +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/debug") echo "Make you sure to 'cargo build' first." ;; + "../../target/debug/release") echo "Make you sure to 'cargo build --release' first." ;; + esac + exit 1 +fi + echo "### Startup time" echo -hyperfine --warmup 3 bat +hyperfine --warmup 3 "$BAT" echo echo "### Plain text" 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 "### Time to syntax-highlight large files" echo 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 From e26ec314638ffbdfdd66d43403f965a59e3ffc5d Mon Sep 17 00:00:00 2001 From: Ethan P Date: Mon, 5 Oct 2020 15:42:00 -0700 Subject: [PATCH 2/3] Add option to specify exact binary in run-benchmarks.sh --- tests/benchmarks/run-benchmarks.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/benchmarks/run-benchmarks.sh b/tests/benchmarks/run-benchmarks.sh index 3e0da33d..d36571a5 100755 --- a/tests/benchmarks/run-benchmarks.sh +++ b/tests/benchmarks/run-benchmarks.sh @@ -13,6 +13,7 @@ for arg in "$@"; do --system) BAT="bat" ;; --debug) BAT="../../target/debug/bat" ;; --release) BAT="../../target/release/bat" ;; + --bat=*) BAT="${arg:6}" ;; esac done From 3ed0081f1fb4b707af026fcf1789909114487975 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Tue, 29 Dec 2020 15:07:22 -0800 Subject: [PATCH 3/3] Improve benchmark script to support cargo/config target-dir --- tests/benchmarks/run-benchmarks.sh | 33 +++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/benchmarks/run-benchmarks.sh b/tests/benchmarks/run-benchmarks.sh index d36571a5..c7f96b4a 100755 --- a/tests/benchmarks/run-benchmarks.sh +++ b/tests/benchmarks/run-benchmarks.sh @@ -1,18 +1,35 @@ #!/usr/bin/env bash cd "$(dirname "${BASH_SOURCE[0]}")" +# Check that Hyperfine is installed. if ! which hyperfine > /dev/null 2>&1; then - echo "'hyperfine' does not seem to be installed." - echo "You can get it here: https://github.com/sharkdp/hyperfine" + echo "'hyperfine' does not seem to be installed." 1>&2 + echo "You can get it here: https://github.com/sharkdp/hyperfine" 1>&2 exit 1 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/bat" ;; - --release) BAT="../../target/release/bat" ;; + --debug) BAT="$TARGET_DEBUG" ;; + --release) BAT="$TARGET_RELEASE" ;; --bat=*) BAT="${arg:6}" ;; esac done @@ -23,16 +40,18 @@ if [[ -z "$BAT" ]]; then 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/debug") echo "Make you sure to 'cargo build' first." ;; - "../../target/debug/release") echo "Make you sure to 'cargo build --release' first." ;; + "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