-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.sh
More file actions
executable file
·97 lines (80 loc) · 1.9 KB
/
bench.sh
File metadata and controls
executable file
·97 lines (80 loc) · 1.9 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
94
95
96
97
#!/usr/bin/env bash
# bench.sh — benchmark nit vs git
#
# Usage: ./bench.sh [repo-path]
# Defaults to current directory. Use a repo with dirty working tree for best results.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
NIT="${NIT:-$SCRIPT_DIR/zig-out/bin/nit}"
REPO="${1:-.}"
# Resolve to absolute path
NIT="$(cd "$(dirname "$NIT")" && pwd)/$(basename "$NIT")"
RUNS=100
if ! command -v hyperfine &>/dev/null; then
echo "error: hyperfine required (brew install hyperfine)"
exit 1
fi
if [ ! -x "$NIT" ]; then
echo "error: nit binary not found at $NIT"
echo " run: zig build -Doptimize=ReleaseFast"
exit 1
fi
cd "$REPO"
echo "=== nit vs git benchmark ==="
echo "repo: $(pwd)"
echo "runs: $RUNS"
echo ""
# --- Speed benchmarks ---
echo "--- status ---"
hyperfine \
--warmup 5 \
--runs "$RUNS" \
--export-markdown /dev/null \
'git status' \
'git status --porcelain -b' \
"$NIT status" \
2>&1
echo ""
echo "--- log (20 commits) ---"
hyperfine \
--warmup 5 \
--runs "$RUNS" \
'git log -20 --oneline' \
'git log -20' \
"$NIT log" \
2>&1
echo ""
echo "--- diff ---"
hyperfine \
--warmup 5 \
--runs "$RUNS" \
'git diff' \
'git diff -U1' \
"$NIT diff" \
2>&1
# --- Token benchmarks ---
echo ""
echo "=== token savings ==="
echo ""
measure() {
local label="$1"
shift
local chars
chars=$("$@" 2>/dev/null | wc -c | tr -d ' ')
local tokens=$((chars / 4))
printf " %-30s %6s chars ~%5s tokens\n" "$label" "$chars" "$tokens"
}
echo "--- status ---"
measure "git status" git status
measure "git status --porcelain -b" git status --porcelain -b
measure "nit status" "$NIT" status
echo ""
echo "--- log (20 commits) ---"
measure "git log -20" git log -20
measure "git log -20 --oneline" git log -20 --oneline
measure "nit log" "$NIT" log
echo ""
echo "--- diff ---"
measure "git diff" git diff
measure "git diff -U1" git diff -U1
measure "nit diff" "$NIT" diff