-
Notifications
You must be signed in to change notification settings - Fork 669
Expand file tree
/
Copy pathrtk-benchmark.sh
More file actions
executable file
·159 lines (133 loc) · 4.97 KB
/
Copy pathrtk-benchmark.sh
File metadata and controls
executable file
·159 lines (133 loc) · 4.97 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
#!/bin/bash
# RTK Benchmark Script for T3 Stack Projects
# Usage: bash .claude/scripts/rtk-benchmark.sh
set -e
echo "RTK Benchmark - T3 Stack Edition"
echo "===================================="
echo ""
# Check RTK installation
if ! command -v rtk &> /dev/null; then
echo "RTK not found. Install from: https://github.com/rtk-ai/rtk"
exit 1
fi
RTK_VERSION=$(rtk --version 2>&1 | head -1)
echo "RTK Version: $RTK_VERSION"
echo ""
# Create results directory
RESULTS_DIR=".claude/docs/rtk-benchmarks"
mkdir -p "$RESULTS_DIR"
TIMESTAMP=$(date +%Y-%m-%d_%H-%M-%S)
RESULTS_FILE="$RESULTS_DIR/benchmark-$TIMESTAMP.md"
echo "# RTK Benchmark Results" > "$RESULTS_FILE"
echo "" >> "$RESULTS_FILE"
echo "**Date**: $(date +%Y-%m-%d)" >> "$RESULTS_FILE"
echo "**RTK Version**: $RTK_VERSION" >> "$RESULTS_FILE"
echo "**Project**: $(basename $PWD)" >> "$RESULTS_FILE"
echo "" >> "$RESULTS_FILE"
echo "---" >> "$RESULTS_FILE"
echo "" >> "$RESULTS_FILE"
# Benchmark function
benchmark() {
local name="$1"
local cmd="$2"
local rtk_cmd="$3"
echo "Testing: $name"
# Baseline
baseline_chars=$(eval "$cmd" 2>&1 | wc -c | awk '{print $1}')
baseline_tokens=$((baseline_chars / 4))
# RTK (if supported)
if [ -n "$rtk_cmd" ]; then
rtk_chars=$(eval "$rtk_cmd" 2>&1 | wc -c | awk '{print $1}')
rtk_tokens=$((rtk_chars / 4))
if [ $baseline_chars -gt 0 ]; then
reduction=$(awk "BEGIN {printf \"%.1f\", (1 - $rtk_chars / $baseline_chars) * 100}")
else
reduction="N/A"
fi
status="OK"
if [ "$rtk_chars" -eq 0 ] || [ "$reduction" = "N/A" ]; then
status="FAIL"
reduction="N/A"
fi
else
rtk_chars="N/A"
rtk_tokens="N/A"
reduction="N/A"
status="Not tested"
fi
# Write to results file
echo "| $name | $baseline_chars | $baseline_tokens | $rtk_chars | $rtk_tokens | $reduction% | $status |" >> "$RESULTS_FILE"
}
# Header
echo "| Command | Baseline (chars) | Baseline (tokens) | RTK (chars) | RTK (tokens) | Reduction | Status |" >> "$RESULTS_FILE"
echo "|---------|------------------|-------------------|-------------|--------------|-----------|--------|" >> "$RESULTS_FILE"
# Git commands
echo ""
echo "Git Commands"
echo "==============="
benchmark "git log -20" "git log -20" "rtk git log -- -20"
benchmark "git status" "git status" "rtk git status"
benchmark "git diff HEAD~1" "git diff HEAD~1" "rtk git diff HEAD~1"
# Find commands
echo ""
echo "Find Commands"
echo "================"
benchmark "find src/ -name '*.ts'" "find src/ -name '*.ts' 2>/dev/null || echo ''" "rtk find '*.ts' src/ 2>/dev/null || echo ''"
benchmark "find src/ -name '*.tsx'" "find src/ -name '*.tsx' 2>/dev/null || echo ''" "rtk find '*.tsx' src/ 2>/dev/null || echo ''"
# pnpm commands
echo ""
echo "pnpm Commands"
echo "=============================="
benchmark "pnpm list --depth=0" "pnpm list --depth=0 2>&1" "rtk pnpm list 2>&1"
benchmark "pnpm outdated" "pnpm outdated 2>&1 || echo 'All packages up-to-date'" "rtk pnpm outdated 2>&1 || echo 'All packages up-to-date'"
# Test framework
echo ""
echo "Test Framework"
echo "==============================="
benchmark "pnpm test (first 50 lines)" "pnpm test 2>&1 | head -50" "rtk vitest run 2>&1 | head -50"
# TypeScript
echo ""
echo "TypeScript Compiler"
echo "===================================="
benchmark "pnpm tsc --noEmit" "pnpm tsc --noEmit 2>&1 || echo 'No errors'" "rtk tsc 2>&1 || echo 'No errors'"
# Prisma
echo ""
echo "Prisma"
echo "======================="
benchmark "pnpm prisma migrate status" "pnpm prisma migrate status 2>&1" "rtk prisma migrate status 2>&1"
# Build
echo ""
echo "Build Tools"
echo "============================"
benchmark "pnpm build (first 30 lines)" "pnpm build 2>&1 | head -30" "rtk next 2>&1 | head -30"
# Cargo (Rust projects)
echo ""
echo "Cargo (Rust)"
echo "============================"
benchmark "cargo test" "cargo test 2>&1 || echo 'No Cargo.toml'" "rtk cargo test 2>&1 || echo 'No Cargo.toml'"
benchmark "cargo build" "cargo build 2>&1 || echo 'No Cargo.toml'" "rtk cargo build 2>&1 || echo 'No Cargo.toml'"
# Python
echo ""
echo "Python"
echo "============================"
benchmark "pytest" "python -m pytest 2>&1 || echo 'No pytest'" "rtk python pytest 2>&1 || echo 'No pytest'"
# Go
echo ""
echo "Go"
echo "============================"
benchmark "go test" "go test ./... 2>&1 || echo 'No go.mod'" "rtk go test 2>&1 || echo 'No go.mod'"
echo "" >> "$RESULTS_FILE"
echo "---" >> "$RESULTS_FILE"
echo "" >> "$RESULTS_FILE"
echo "**Legend**:" >> "$RESULTS_FILE"
echo "- OK: RTK filtering successful" >> "$RESULTS_FILE"
echo "- FAIL: RTK returned error or 0 bytes" >> "$RESULTS_FILE"
echo "- Not tested: Command not benchmarked with RTK" >> "$RESULTS_FILE"
echo "" >> "$RESULTS_FILE"
echo "**Token estimation**: chars / 4 ~ tokens (rough approximation)" >> "$RESULTS_FILE"
echo ""
echo "Benchmark complete!"
echo "Results saved to: $RESULTS_FILE"
echo ""
echo "Summary:"
cat "$RESULTS_FILE" | grep "^|" | tail -n +2