-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench.sh
More file actions
executable file
·93 lines (77 loc) · 2.15 KB
/
bench.sh
File metadata and controls
executable file
·93 lines (77 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <file.ndc>" >&2
exit 1
fi
FILE="$1"
if [[ ! -f "$FILE" ]]; then
echo "Error: file not found: $FILE" >&2
exit 1
fi
if ! command -v ndc &>/dev/null; then
echo "Error: 'ndc' not found in PATH" >&2
exit 1
fi
if ! command -v hyperfine &>/dev/null; then
echo "Error: 'hyperfine' not found in PATH" >&2
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOCAL="$SCRIPT_DIR/target/release/ndc"
echo "Building release binary..."
cargo build --release --manifest-path "$SCRIPT_DIR/Cargo.toml" -q
echo ""
echo "Validating versions can run '$FILE' without crashing..."
validate() {
local label="$1"
local cmd=("${@:2}")
if ! "${cmd[@]}" &>/dev/null; then
echo " FAIL: $label crashed or returned an error" >&2
exit 1
fi
echo " OK: $label"
}
validate "ndc (PATH)" ndc run "$FILE"
validate "local release (VM)" "$LOCAL" run "$FILE"
# ndc2 and ndc1 are optional: older versions may not support all language features
# ndc1 also has a different CLI (no 'run' subcommand)
USE_NDC2=false
if command -v ndc2 &>/dev/null; then
if ndc2 run "$FILE" &>/dev/null; then
echo " OK: ndc2 (v0.2.1)"
USE_NDC2=true
else
echo " SKIP: ndc2 (v0.2.1) failed to run '$FILE', skipping"
fi
else
echo " SKIP: ndc2 not found, skipping"
fi
USE_NDC1=false
if command -v ndc1 &>/dev/null; then
if ndc1 "$FILE" &>/dev/null; then
echo " OK: ndc1 (v0.1.0)"
USE_NDC1=true
else
echo " SKIP: ndc1 (v0.1.0) failed to run '$FILE', skipping"
fi
else
echo " SKIP: ndc1 not found, skipping"
fi
echo ""
echo "Running benchmark..."
echo ""
NDC2_ARGS=()
if [[ "$USE_NDC2" == true ]]; then
NDC2_ARGS=(--command-name "ndc2 (v0.2.1)" "ndc2 run '$FILE'")
fi
NDC1_ARGS=()
if [[ "$USE_NDC1" == true ]]; then
NDC1_ARGS=(--command-name "ndc1 (v0.1.0)" "ndc1 '$FILE'")
fi
hyperfine \
--warmup 3 \
--command-name "ndc (installed)" "ndc run '$FILE'" \
--command-name "local release (VM)" "'$LOCAL' run '$FILE'" \
"${NDC2_ARGS[@]}" \
"${NDC1_ARGS[@]}"