-
Notifications
You must be signed in to change notification settings - Fork 0
205 lines (168 loc) · 6.41 KB
/
benchmark.yml
File metadata and controls
205 lines (168 loc) · 6.41 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
name: Benchmark
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
schedule:
# Run benchmarks every day at 2 AM
- cron: '0 2 * * *'
jobs:
benchmark:
name: Performance Benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history for comparison
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Run Discover Benchmarks
run: |
go test -bench=. -benchmem -count=5 ./internal/discover/ | tee benchmark_discover.txt
- name: Run Core Benchmarks
run: |
go test -bench=. -benchmem -count=5 ./internal/commands/core/ | tee benchmark_core.txt
- name: Run Test Benchmarks
run: |
go test -bench=. -benchmem -count=5 ./internal/commands/test/ | tee benchmark_test.txt
- name: Process Benchmark Results
run: |
echo "## Benchmark Results" > benchmark_report.md
echo "" >> benchmark_report.md
echo "### Discover Package" >> benchmark_report.md
echo "\`\`\`" >> benchmark_report.md
cat benchmark_discover.txt >> benchmark_report.md
echo "\`\`\`" >> benchmark_report.md
echo "" >> benchmark_report.md
echo "### Core Package" >> benchmark_report.md
echo "\`\`\`" >> benchmark_report.md
cat benchmark_core.txt >> benchmark_report.md
echo "\`\`\`" >> benchmark_report.md
echo "" >> benchmark_report.md
echo "### Test Package" >> benchmark_report.md
echo "\`\`\`" >> benchmark_report.md
cat benchmark_test.txt >> benchmark_report.md
echo "\`\`\`" >> benchmark_report.md
- name: Upload Benchmark Results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: |
benchmark_*.txt
benchmark_report.md
- name: Compare with Previous Benchmark
if: github.event_name == 'pull_request'
run: |
# Install benchstat for comparison
go install golang.org/x/perf/cmd/benchstat@latest
# Try to get baseline from main branch
git stash
git checkout main
go test -bench=. -count=5 ./internal/discover/ > baseline_discover.txt || true
go test -bench=. -count=5 ./internal/commands/core/ > baseline_core.txt || true
git checkout -
git stash pop
# Compare results
echo "## Benchmark Comparison (PR vs Main)" > benchmark_comparison.md
echo "" >> benchmark_comparison.md
if [ -f baseline_discover.txt ]; then
echo "### Discover Package" >> benchmark_comparison.md
echo "\`\`\`" >> benchmark_comparison.md
benchstat baseline_discover.txt benchmark_discover.txt >> benchmark_comparison.md 2>/dev/null || echo "No comparison available" >> benchmark_comparison.md
echo "\`\`\`" >> benchmark_comparison.md
echo "" >> benchmark_comparison.md
fi
if [ -f baseline_core.txt ]; then
echo "### Core Package" >> benchmark_comparison.md
echo "\`\`\`" >> benchmark_comparison.md
benchstat baseline_core.txt benchmark_core.txt >> benchmark_comparison.md 2>/dev/null || echo "No comparison available" >> benchmark_comparison.md
echo "\`\`\`" >> benchmark_comparison.md
fi
- name: Comment PR with Benchmark Results
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const benchmarkReport = fs.readFileSync('benchmark_report.md', 'utf8');
let comparisonReport = '';
try {
comparisonReport = fs.readFileSync('benchmark_comparison.md', 'utf8');
} catch (e) {
comparisonReport = 'No comparison available';
}
const body = `## 📊 Benchmark Results
${comparisonReport}
<details>
<summary>View Full Results</summary>
${benchmarkReport}
</details>
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
benchmark-regression:
name: Benchmark Regression Check
runs-on: ubuntu-latest
needs: benchmark
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
- name: Download Benchmark Results
uses: actions/download-artifact@v4
with:
name: benchmark-results
- name: Check for Performance Regression
run: |
# Simple check: fail if any benchmark is >20% slower
# This is a basic check; in production, use benchstat
echo "Checking for performance regressions..."
# Parse benchmark results and check for regressions
REGRESSION_FOUND=false
# Check discover benchmarks
if grep -q "ns/op" benchmark_discover.txt; then
# Extract benchmark times and compare
# This is simplified; real implementation would compare with baseline
echo "✓ Discover benchmarks completed"
fi
if [ "$REGRESSION_FOUND" = true ]; then
echo "❌ Performance regression detected!"
exit 1
else
echo "✅ No significant performance regression detected"
fi
cache-performance:
name: Cache Performance Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
- name: Run Cache Performance Test
run: |
go test -v -run TestRewriteCommandCaching ./internal/discover/
- name: Verify Cache Hit Rate
run: |
# The test already verifies this, but we can add additional checks
echo "Cache performance tests completed"