File tree Expand file tree Collapse file tree 2 files changed +84
-0
lines changed
Expand file tree Collapse file tree 2 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Benchmark Regression Check
2+
3+ on :
4+ pull_request :
5+ branches : [ main ]
6+
7+ jobs :
8+ benchmark :
9+ runs-on : ubuntu-latest
10+
11+ steps :
12+ - name : Checkout PR branch
13+ uses : actions/checkout@v4
14+ with :
15+ fetch-depth : 0 # important to access main branch
16+
17+ - name : Set up Go
18+ uses : actions/setup-go@v5.4.0
19+ with :
20+ go-version : ' 1.24'
21+ check-latest : true
22+ cache-dependency-path : go.sum
23+
24+ - name : Install benchstat
25+ run : go install golang.org/x/perf/cmd/benchstat@latest
26+
27+ - name : Run benchmarks on PR branch
28+ run : go test -bench=. -benchmem ./... > pr.txt
29+
30+ - name : Create worktree for origin/main
31+ run : |
32+ git fetch origin main
33+ git worktree add ../main-worktree origin/main
34+
35+ - name : Run benchmark for origin/main
36+ run : |
37+ cd ../main-worktree
38+ go test -bench=BenchmarkSamplesJsonSerialization -benchmem ./... > ../main.txt
39+ cd -
40+ rm -rf ../main-worktree
41+
42+ - name : Check for regressions
43+ run : |
44+ ls -l
45+ bash .github/workflows/check-bench.sh ../main.txt pr.txt
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ set -euo pipefail
4+
5+ main_file=" $1 "
6+ pr_file=" $2 "
7+ threshold=20
8+
9+ echo " Comparing benchmark results..."
10+
11+ benchstat " $main_file " " $pr_file " > result.txt
12+ cat result.txt
13+
14+ # Fail if regression exceeds threshold
15+ fail=0
16+ awk -v threshold=$threshold '
17+ /±/ {
18+ split($1, name, "-")
19+ name = name[1]
20+ old = $3
21+ new = $6
22+ delta = $7
23+
24+ if (match(delta, /\+([0-9.]+)%/, m)) {
25+ change = m[1]
26+ if (change > threshold) {
27+ printf "❌ %s regressed by %s%%\n", name, change
28+ exit 1
29+ }
30+ }
31+ }
32+ ' result.txt || fail=1
33+
34+ if [ " $fail " -eq 1 ]; then
35+ echo " 🚨 Performance regression > $threshold % detected!"
36+ exit 1
37+ else
38+ echo " ✅ No significant regressions detected."
39+ fi
You can’t perform that action at this time.
0 commit comments