Skip to content

Commit ecb22ab

Browse files
ci(GitHub): add benchmark action
1 parent 73a9f09 commit ecb22ab

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

.github/workflows/benchmark.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Benchmark
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
benchmark:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup Go environment
21+
uses: actions/setup-go@v4
22+
with:
23+
go-version: 1.25.1
24+
25+
- name: Install benchstat
26+
run: go install golang.org/x/perf/cmd/benchstat@latest
27+
28+
- name: Run benchmarks on base branch
29+
if: github.event_name == 'pull_request'
30+
run: |
31+
git checkout ${{ github.event.pull_request.base.sha }}
32+
go mod tidy
33+
go test -bench . -count 7 -benchmem > base-bench.txt
34+
git checkout ${{ github.event.pull_request.head.sha }}
35+
36+
- name: Run benchmarks on current commit
37+
run: |
38+
go mod tidy
39+
go test -bench . -count 7 -benchmem > current-bench.txt
40+
41+
- name: Compare benchmarks
42+
if: github.event_name == 'pull_request'
43+
run: |
44+
cat > benchmark-comment.md << EOF
45+
## Benchmark Results
46+
47+
\`\`\`
48+
$(benchstat base-bench.txt current-bench.txt || echo "No significant differences found.")
49+
\`\`\`
50+
EOF
51+
52+
- name: Comment PR with benchmark results
53+
if: github.event_name == 'pull_request'
54+
uses: actions/github-script@v6
55+
with:
56+
script: |
57+
const fs = require('fs');
58+
const comment = fs.readFileSync('benchmark-comment.md', 'utf8');
59+
github.rest.issues.createComment({
60+
issue_number: context.issue.number,
61+
owner: context.repo.owner,
62+
repo: context.repo.repo,
63+
body: comment
64+
});
65+
66+
- name: Check for significant regressions
67+
if: github.event_name == 'pull_request'
68+
run: |
69+
# Parse benchstat output for significant regressions
70+
if benchstat base-bench.txt current-bench.txt | grep -E '\+[0-9]+\.[0-9]+%.*p=0\.[0-9]+' | grep -v '~'; then
71+
echo "::warning::Potential performance regression detected. Review benchmark results."
72+
fi

0 commit comments

Comments
 (0)