forked from rtk-ai/rtk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.sh
More file actions
executable file
·690 lines (589 loc) · 20.2 KB
/
Copy pathbenchmark.sh
File metadata and controls
executable file
·690 lines (589 loc) · 20.2 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
#!/usr/bin/env bash
set -e
# Use local release build if available, otherwise fall back to installed rtk
if [ -f "./target/release/rtk" ]; then
RTK="$(cd "$(dirname ./target/release/rtk)" && pwd)/$(basename ./target/release/rtk)"
elif command -v rtk &> /dev/null; then
RTK="$(command -v rtk)"
else
echo "Error: rtk not found. Run 'cargo build --release' or install rtk."
exit 1
fi
BENCH_DIR="$(pwd)/scripts/benchmark"
RTK_ROOT="$(pwd)"
if [ -z "$CI" ]; then
rm -rf "$BENCH_DIR"
mkdir -p "$BENCH_DIR/unix" "$BENCH_DIR/rtk" "$BENCH_DIR/diff"
fi
safe_name() {
echo "$1" | tr ' /' '_-' | tr -cd 'a-zA-Z0-9_-'
}
count_tokens() {
local input="$1"
local len=${#input}
echo $(( (len + 3) / 4 ))
}
TOTAL_UNIX=0
TOTAL_RTK=0
TOTAL_TESTS=0
GOOD_TESTS=0
FAIL_TESTS=0
WARN_TESTS=0
NEGATIVE_TESTS=0
bench() {
local name="$1"
local unix_cmd="$2"
local rtk_cmd="$3"
unix_out=$(eval "$unix_cmd" 2>/dev/null || true)
rtk_out=$(eval "$rtk_cmd" 2>/dev/null || true)
unix_tokens=$(count_tokens "$unix_out")
rtk_tokens=$(count_tokens "$rtk_out")
TOTAL_TESTS=$((TOTAL_TESTS + 1))
local icon=""
local tag=""
if [ -z "$rtk_out" ] && [ -n "$unix_out" ]; then
icon="❌"
tag="FAIL"
FAIL_TESTS=$((FAIL_TESTS + 1))
TOTAL_UNIX=$((TOTAL_UNIX + unix_tokens))
TOTAL_RTK=$((TOTAL_RTK + unix_tokens))
elif [ "$rtk_tokens" -gt "$unix_tokens" ] && [ "$unix_tokens" -gt 0 ]; then
icon="🔴"
tag="NEG"
NEGATIVE_TESTS=$((NEGATIVE_TESTS + 1))
TOTAL_UNIX=$((TOTAL_UNIX + unix_tokens))
TOTAL_RTK=$((TOTAL_RTK + rtk_tokens))
elif [ "$unix_tokens" -gt 0 ] && [ "$rtk_tokens" -eq "$unix_tokens" ]; then
icon="⚠️"
tag="WARN"
WARN_TESTS=$((WARN_TESTS + 1))
TOTAL_UNIX=$((TOTAL_UNIX + unix_tokens))
TOTAL_RTK=$((TOTAL_RTK + rtk_tokens))
elif [ "$unix_tokens" -gt 0 ]; then
local savings=$(( (unix_tokens - rtk_tokens) * 100 / unix_tokens ))
if [ "$savings" -lt 60 ]; then
icon="⚠️"
tag="WARN"
WARN_TESTS=$((WARN_TESTS + 1))
else
icon="✅"
tag="GOOD"
GOOD_TESTS=$((GOOD_TESTS + 1))
fi
TOTAL_UNIX=$((TOTAL_UNIX + unix_tokens))
TOTAL_RTK=$((TOTAL_RTK + rtk_tokens))
else
icon="⏭️"
tag="SKIP"
WARN_TESTS=$((WARN_TESTS + 1))
fi
if [ "$tag" = "FAIL" ]; then
printf "%s %-24s │ %-40s │ %-40s │ %6d → %6s (--)\n" \
"$icon" "$name" "$unix_cmd" "$rtk_cmd" "$unix_tokens" "-"
else
if [ "$unix_tokens" -gt 0 ]; then
local pct=$(( (unix_tokens - rtk_tokens) * 100 / unix_tokens ))
else
local pct=0
fi
printf "%s %-24s │ %-40s │ %-40s │ %6d → %6d (%+d%%)\n" \
"$icon" "$name" "$unix_cmd" "$rtk_cmd" "$unix_tokens" "$rtk_tokens" "$pct"
fi
if [ -z "$CI" ]; then
local filename=$(safe_name "$name")
local prefix="GOOD"
[ "$tag" = "FAIL" ] && prefix="FAIL"
[ "$tag" = "NEG" ] && prefix="NEG"
[ "$tag" = "WARN" ] && prefix="WARN"
[ "$tag" = "SKIP" ] && prefix="SKIP"
local ts=$(date "+%d/%m/%Y %H:%M:%S")
printf "# %s\n> %s\n\n\`\`\`bash\n$ %s\n\`\`\`\n\n\`\`\`\n%s\n\`\`\`\n" \
"$name" "$ts" "$unix_cmd" "$unix_out" > "$BENCH_DIR/unix/${filename}.md"
printf "# %s\n> %s\n\n\`\`\`bash\n$ %s\n\`\`\`\n\n\`\`\`\n%s\n\`\`\`\n" \
"$name" "$ts" "$rtk_cmd" "$rtk_out" > "$BENCH_DIR/rtk/${filename}.md"
{
echo "# Diff: $name"
echo "> $ts"
echo ""
echo "| Metric | Unix | RTK |"
echo "|--------|------|-----|"
echo "| Tokens | $unix_tokens | $rtk_tokens |"
echo ""
echo "## Unix"
echo "\`\`\`"
echo "$unix_out"
echo "\`\`\`"
echo ""
echo "## RTK"
echo "\`\`\`"
echo "$rtk_out"
echo "\`\`\`"
} > "$BENCH_DIR/diff/${prefix}-${filename}.md"
fi
}
section() {
echo ""
echo "── $1 ──"
}
# ═══════════════════════════════════════════
echo "RTK Benchmark"
echo "═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════"
printf " %-24s │ %-40s │ %-40s │ %s\n" "TEST" "SHELL" "RTK" "TOKENS"
echo "───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────"
# ===================
# ls
# ===================
section "ls"
bench "ls" "ls -la" "$RTK ls"
bench "ls src/" "ls -la src/" "$RTK ls src/"
bench "ls -l src/" "ls -l src/" "$RTK ls -l src/"
bench "ls -la src/" "ls -la src/" "$RTK ls -la src/"
bench "ls -lh src/" "ls -lh src/" "$RTK ls -lh src/"
bench "ls src/ -l" "ls -l src/" "$RTK ls src/ -l"
bench "ls -a" "ls -la" "$RTK ls -a"
bench "ls multi" "ls -la src/ scripts/" "$RTK ls src/ scripts/"
# ===================
# tree
# ===================
if command -v tree &>/dev/null; then
section "tree"
bench "tree" "tree -L 2" "$RTK tree -L 2"
bench "tree src/" "tree src/ -L 2" "$RTK tree src/ -L 2"
else
echo ""
echo "⏭️ tree (not installed, skipped)"
fi
# ===================
# read
# ===================
section "read"
bench "read" "cat src/main.rs" "$RTK read src/main.rs"
bench "read -l minimal" "cat src/main.rs" "$RTK read src/main.rs -l minimal"
bench "read -l aggressive" "cat src/main.rs" "$RTK read src/main.rs -l aggressive"
bench "read -n" "cat -n src/main.rs" "$RTK read src/main.rs -n"
# ===================
# find
# ===================
section "find"
bench "find *" "find . -type f" "$RTK find '*'"
bench "find *.rs" "find . -name '*.rs' -type f" "$RTK find '*.rs'"
bench "find --max 10" "find . -not -path './target/*' -not -path './.git/*' -type f | head -10" "$RTK find '*' --max 10"
bench "find --max 100" "find . -not -path './target/*' -not -path './.git/*' -type f | head -100" "$RTK find '*' --max 100"
# ===================
# git
# ===================
section "git"
bench "git status" "git status" "$RTK git status"
bench "git log -n 10" "git log -10" "$RTK git log -n 10"
bench "git log -n 5" "git log -5" "$RTK git log -n 5"
bench "git diff" "git diff HEAD~1 2>/dev/null || echo ''" "$RTK git diff HEAD~1"
bench "git show" "git show HEAD --stat 2>/dev/null || true" "$RTK git show HEAD --stat"
# ===================
# grep
# ===================
section "grep"
bench "grep fn" "grep -rn 'fn ' src/ || true" "$RTK grep 'fn ' src/"
bench "grep struct" "grep -rn 'struct ' src/ || true" "$RTK grep 'struct ' src/"
bench "grep -l 40" "grep -rn 'fn ' src/ || true" "$RTK grep 'fn ' src/ -l 40"
bench "grep -c" "grep -ron 'fn ' src/ || true" "$RTK grep 'fn ' src/ -c"
# ===================
# json
# ===================
section "json"
cat > /tmp/rtk_bench.json << 'JSONEOF'
{
"name": "rtk",
"version": "0.2.1",
"config": {
"debug": false,
"max_depth": 10,
"filters": ["node_modules", "target", ".git"]
},
"dependencies": {
"serde": "1.0",
"clap": "4.0",
"anyhow": "1.0"
}
}
JSONEOF
bench "json" "cat /tmp/rtk_bench.json" "$RTK json /tmp/rtk_bench.json"
bench "json -d 2" "cat /tmp/rtk_bench.json" "$RTK json /tmp/rtk_bench.json -d 2"
rm -f /tmp/rtk_bench.json
# ===================
# deps
# ===================
section "deps"
bench "deps" "cat Cargo.toml" "$RTK deps"
# ===================
# env
# ===================
section "env"
bench "env" "env" "$RTK env"
bench "env -f PATH" "env | grep PATH" "$RTK env -f PATH"
bench "env --show-all" "env" "$RTK env --show-all"
# ===================
# err
# ===================
section "err"
if command -v cargo &>/dev/null; then
bench "err cargo build" "cargo build 2>&1 || true" "$RTK err cargo build 2>&1"
else
echo "⏭️ err cargo build (cargo not in PATH, skipped)"
fi
# ===================
# test
# ===================
section "test"
if command -v cargo &>/dev/null; then
bench "test cargo test" "cargo test 2>&1 || true" "$RTK test cargo test 2>&1"
else
echo "⏭️ test cargo test (cargo not in PATH, skipped)"
fi
# ===================
# log
# ===================
section "log"
LOG_FILE="/tmp/rtk_bench_sample.log"
cat > "$LOG_FILE" << 'LOGEOF'
2024-01-15 10:00:01 INFO Application started
2024-01-15 10:00:02 INFO Loading configuration
2024-01-15 10:00:03 ERROR Connection failed: timeout
2024-01-15 10:00:04 ERROR Connection failed: timeout
2024-01-15 10:00:05 ERROR Connection failed: timeout
2024-01-15 10:00:06 ERROR Connection failed: timeout
2024-01-15 10:00:07 ERROR Connection failed: timeout
2024-01-15 10:00:08 WARN Retrying connection
2024-01-15 10:00:09 INFO Connection established
2024-01-15 10:00:10 INFO Processing request
2024-01-15 10:00:11 INFO Processing request
2024-01-15 10:00:12 INFO Processing request
2024-01-15 10:00:13 INFO Request completed
LOGEOF
bench "log" "cat $LOG_FILE" "$RTK log $LOG_FILE"
rm -f "$LOG_FILE"
# ===================
# summary
# ===================
section "summary"
if command -v cargo &>/dev/null; then
bench "summary cargo --help" "cargo --help" "$RTK summary cargo --help"
else
echo "⏭️ summary cargo --help (cargo not in PATH, skipped)"
fi
if command -v rustc &>/dev/null; then
bench "summary rustc --help" "rustc --help 2>/dev/null || echo 'rustc not found'" "$RTK summary rustc --help"
else
echo "⏭️ summary rustc --help (rustc not in PATH, skipped)"
fi
# ===================
# cargo
# ===================
section "cargo"
if command -v cargo &>/dev/null; then
bench "cargo build" "cargo build 2>&1 || true" "$RTK cargo build 2>&1"
bench "cargo test" "cargo test 2>&1 || true" "$RTK cargo test 2>&1"
bench "cargo clippy" "cargo clippy 2>&1 || true" "$RTK cargo clippy 2>&1"
bench "cargo check" "cargo check 2>&1 || true" "$RTK cargo check 2>&1"
else
echo "⏭️ cargo build/test/clippy/check (cargo not in PATH, skipped)"
fi
# ===================
# smart
# ===================
section "smart"
bench "smart main.rs" "cat src/main.rs" "$RTK smart src/main.rs"
# ===================
# wc
# ===================
section "wc"
bench "wc" "wc Cargo.toml src/main.rs" "$RTK wc Cargo.toml src/main.rs"
# ===================
# curl
# ===================
section "curl"
if command -v curl &> /dev/null; then
bench "curl json" "curl -s https://httpbin.org/json" "$RTK curl https://httpbin.org/json"
bench "curl text" "curl -s https://httpbin.org/robots.txt" "$RTK curl https://httpbin.org/robots.txt"
fi
# ===================
# wget
# ===================
if command -v wget &> /dev/null; then
section "wget"
bench "wget" "wget -qO- https://httpbin.org/json" "$RTK wget https://httpbin.org/json"
rm -f json 2>/dev/null
fi
# ===================
# npm (standalone — does not require package.json)
# ===================
if command -v npm &> /dev/null; then
section "npm"
bench "npm list" "npm list -g --depth 0 2>&1 || true" "$RTK npm list -g --depth 0"
fi
# ===================
# Modern JavaScript Stack (skip si pas de package.json)
# ===================
if [ -f "package.json" ]; then
section "modern JS stack"
if command -v tsc &> /dev/null || [ -f "node_modules/.bin/tsc" ]; then
bench "tsc" "tsc --noEmit 2>&1 || true" "$RTK tsc --noEmit 2>&1"
fi
if command -v prettier &> /dev/null || [ -f "node_modules/.bin/prettier" ]; then
bench "prettier --check" "prettier --check . 2>&1 || true" "$RTK prettier --check ."
fi
if command -v eslint &> /dev/null || [ -f "node_modules/.bin/eslint" ]; then
bench "lint" "eslint . 2>&1 || true" "$RTK lint ."
fi
if [ -f "next.config.js" ] || [ -f "next.config.mjs" ] || [ -f "next.config.ts" ]; then
if command -v next &> /dev/null || [ -f "node_modules/.bin/next" ]; then
bench "next build" "next build 2>&1 || true" "$RTK next build"
fi
fi
if [ -f "playwright.config.ts" ] || [ -f "playwright.config.js" ]; then
if command -v playwright &> /dev/null || [ -f "node_modules/.bin/playwright" ]; then
bench "playwright test" "playwright test 2>&1 || true" "$RTK playwright test"
fi
fi
if [ -f "prisma/schema.prisma" ]; then
if command -v prisma &> /dev/null || [ -f "node_modules/.bin/prisma" ]; then
bench "prisma generate" "prisma generate 2>&1 || true" "$RTK prisma generate"
fi
fi
if command -v vitest &> /dev/null || [ -f "node_modules/.bin/vitest" ]; then
bench "vitest" "vitest run --reporter=json 2>&1 || true" "$RTK vitest"
fi
if command -v pnpm &> /dev/null; then
bench "pnpm list" "pnpm list --depth 0 2>&1 || true" "$RTK pnpm list --depth 0"
bench "pnpm outdated" "pnpm outdated 2>&1 || true" "$RTK pnpm outdated"
fi
fi
# ===================
# gh (skip si pas dispo ou pas dans un repo)
# ===================
if command -v gh &> /dev/null && git rev-parse --git-dir &> /dev/null && gh auth status &> /dev/null; then
section "gh"
bench "gh pr list" "gh pr list 2>&1 || true" "$RTK gh pr list"
bench "gh run list" "gh run list 2>&1 || true" "$RTK gh run list"
fi
# ===================
# glab
# ===================
if command -v glab &> /dev/null; then
section "glab"
bench "glab mr list" "glab mr list 2>&1 || true" "$RTK glab mr list"
bench "glab issue list" "glab issue list 2>&1 || true" "$RTK glab issue list"
fi
# ===================
# gt (Graphite)
# ===================
if command -v gt &> /dev/null; then
section "gt"
bench "gt log" "gt log 2>&1 || true" "$RTK gt log"
fi
# ===================
# docker
# ===================
if command -v docker &> /dev/null; then
section "docker"
bench "docker ps" "docker ps 2>/dev/null || true" "$RTK docker ps"
bench "docker images" "docker images 2>/dev/null || true" "$RTK docker images"
fi
# ===================
# kubectl
# ===================
if command -v kubectl &> /dev/null; then
section "kubectl"
bench "kubectl pods" "kubectl get pods 2>/dev/null || true" "$RTK kubectl pods"
bench "kubectl services" "kubectl get services 2>/dev/null || true" "$RTK kubectl services"
fi
# ===================
# Python (avec fixtures temporaires)
# ===================
if command -v python3 &> /dev/null && command -v ruff &> /dev/null && command -v pytest &> /dev/null; then
section "python"
PYTHON_FIXTURE=$(mktemp -d)
cd "$PYTHON_FIXTURE"
cat > pyproject.toml << 'PYEOF'
[project]
name = "rtk-bench"
version = "0.1.0"
[tool.ruff]
line-length = 88
PYEOF
cat > sample.py << 'PYEOF'
import os
import sys
import json
def process_data(x):
if x == None: # E711: comparison to None
return []
result = []
for i in range(len(x)): # C416: unnecessary list comprehension
result.append(x[i] * 2)
return result
def unused_function(): # F841: local variable assigned but never used
temp = 42
return None
PYEOF
cat > test_sample.py << 'PYEOF'
from sample import process_data
def test_process_data():
assert process_data([1, 2, 3]) == [2, 4, 6]
def test_process_data_none():
assert process_data(None) == []
PYEOF
bench "ruff check" "ruff check . 2>&1 || true" "$RTK ruff check ."
bench "pytest" "pytest -v 2>&1 || true" "$RTK pytest -v"
if command -v pip &>/dev/null; then
bench "pip list" "pip list 2>&1 || true" "$RTK pip list"
fi
if command -v mypy &>/dev/null; then
bench "mypy" "mypy sample.py 2>&1 || true" "$RTK mypy sample.py"
fi
cd "$RTK_ROOT"
rm -rf "$PYTHON_FIXTURE"
fi
# ===================
# Go (avec fixtures temporaires)
# ===================
if command -v go &> /dev/null && command -v golangci-lint &> /dev/null; then
section "go"
GO_FIXTURE=$(mktemp -d)
cd "$GO_FIXTURE"
cat > go.mod << 'GOEOF'
module bench
go 1.21
GOEOF
cat > main.go << 'GOEOF'
package main
import "fmt"
func Add(a, b int) int {
return a + b
}
func Multiply(a, b int) int {
return a * b
}
func main() {
fmt.Println(Add(2, 3))
fmt.Println(Multiply(4, 5))
}
GOEOF
cat > main_test.go << 'GOEOF'
package main
import "testing"
func TestAdd(t *testing.T) {
result := Add(2, 3)
if result != 5 {
t.Errorf("Add(2, 3) = %d; want 5", result)
}
}
func TestMultiply(t *testing.T) {
result := Multiply(4, 5)
if result != 20 {
t.Errorf("Multiply(4, 5) = %d; want 20", result)
}
}
GOEOF
bench "golangci-lint" "golangci-lint run 2>&1 || true" "$RTK golangci-lint run"
bench "go test" "go test -v 2>&1 || true" "$RTK go test -v"
bench "go build" "go build ./... 2>&1 || true" "$RTK go build ./..."
bench "go vet" "go vet ./... 2>&1 || true" "$RTK go vet ./..."
cd "$RTK_ROOT"
rm -rf "$GO_FIXTURE"
fi
# ===================
# Ruby
# ===================
if command -v ruby &> /dev/null; then
section "ruby"
if command -v rake &>/dev/null; then
bench "rake -T" "rake -T 2>&1 || true" "$RTK rake -T"
fi
if command -v rubocop &>/dev/null; then
bench "rubocop" "rubocop --format simple 2>&1 || true" "$RTK rubocop --format simple"
fi
if command -v rspec &>/dev/null; then
bench "rspec --dry-run" "rspec --dry-run 2>&1 || true" "$RTK rspec --dry-run"
fi
fi
# ===================
# dotnet
# ===================
if command -v dotnet &> /dev/null; then
section "dotnet"
bench "dotnet --info" "dotnet --info 2>&1 || true" "$RTK dotnet --info"
fi
# ===================
# aws
# ===================
if command -v aws &> /dev/null; then
section "aws"
bench "aws --version" "aws --version 2>&1 || true" "$RTK aws --version"
fi
# ===================
# psql
# ===================
if command -v psql &> /dev/null; then
section "psql"
bench "psql --version" "psql --version 2>&1 || true" "$RTK psql --version"
fi
# ===================
# rewrite (verify rewrite works with and without quotes)
# ===================
section "rewrite"
bench_rewrite() {
local name="$1"
local cmd="$2"
local expected="$3"
result=$(eval "$cmd" 2>&1 || true)
TOTAL_TESTS=$((TOTAL_TESTS + 1))
if [ "$result" = "$expected" ]; then
printf "✅ %-24s │ %-40s │ %s\n" "$name" "$cmd" "$result"
GOOD_TESTS=$((GOOD_TESTS + 1))
else
printf "❌ %-24s │ %-40s │ got: %s (expected: %s)\n" "$name" "$cmd" "$result" "$expected"
FAIL_TESTS=$((FAIL_TESTS + 1))
fi
}
bench_rewrite "rewrite quoted" "$RTK rewrite 'git status'" "rtk git status"
bench_rewrite "rewrite unquoted" "$RTK rewrite git status" "rtk git status"
bench_rewrite "rewrite ls -al" "$RTK rewrite ls -al" "rtk ls -al"
bench_rewrite "rewrite npm exec" "$RTK rewrite npm exec" "rtk npm exec"
bench_rewrite "rewrite cargo test" "$RTK rewrite cargo test" "rtk cargo test"
bench_rewrite "rewrite compound" "$RTK rewrite 'cargo test && git push'" "rtk cargo test && rtk git push"
# ===================
# Summary
# ===================
echo ""
echo "═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════"
if [ "$TOTAL_TESTS" -gt 0 ]; then
GOOD_PCT=$((GOOD_TESTS * 100 / TOTAL_TESTS))
if [ "$TOTAL_UNIX" -gt 0 ]; then
TOTAL_SAVED=$((TOTAL_UNIX - TOTAL_RTK))
TOTAL_SAVE_PCT=$((TOTAL_SAVED * 100 / TOTAL_UNIX))
else
TOTAL_SAVED=0
TOTAL_SAVE_PCT=0
fi
echo ""
echo " ✅ $GOOD_TESTS good ⚠️ $WARN_TESTS warn 🔴 $NEGATIVE_TESTS negative ❌ $FAIL_TESTS fail $GOOD_TESTS/$TOTAL_TESTS ($GOOD_PCT%)"
echo " Tokens: $TOTAL_UNIX → $TOTAL_RTK (-$TOTAL_SAVE_PCT%)"
echo ""
if [ -z "$CI" ]; then
echo " Debug: $BENCH_DIR/{unix,rtk,diff}/"
fi
echo ""
EXIT_CODE=0
if [ "$NEGATIVE_TESTS" -gt 0 ]; then
echo " BENCHMARK FAILED: $NEGATIVE_TESTS filter(s) produced more tokens than raw output"
EXIT_CODE=1
fi
if [ "$FAIL_TESTS" -gt 0 ]; then
echo " BENCHMARK FAILED: $FAIL_TESTS filter(s) returned empty output"
EXIT_CODE=1
fi
if [ "$GOOD_PCT" -lt 60 ] && [ "$EXIT_CODE" -eq 0 ]; then
echo " WARNING: $GOOD_PCT% good (target 60%)"
fi
exit $EXIT_CODE
fi