Skip to content

Commit 31c9fa4

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

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

.github/workflows/benchmark.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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@v5
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup Go environment
21+
uses: actions/setup-go@v6
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 benchmark 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 -v -run ^$ -bench . -count ${{ vars.GO_BENCHMARK_COUNT }} -benchmem > base-bench.txt
34+
git checkout ${{ github.event.pull_request.head.sha }}
35+
36+
- name: Run benchmark on HEAD commit
37+
run: |
38+
go mod tidy
39+
go test -v -run ^$ -bench . -count ${{ vars.GO_BENCHMARK_COUNT }} -benchmem > head-bench.txt
40+
41+
- name: Compare benchmarks
42+
if: github.event_name == 'pull_request'
43+
run: |
44+
cat > benchmark-comment.md << EOF
45+
## Benchmark comparison w/ base branch
46+
47+
\`\`\`
48+
$(benchstat base-bench.txt head-bench.txt)
49+
\`\`\`
50+
EOF
51+
52+
- name: Comment PR w/ benchmark comparison
53+
if: github.event_name == 'pull_request'
54+
uses: actions/github-script@v8
55+
with:
56+
script: |
57+
github.rest.issues.createComment({
58+
issue_number: context.issue.number,
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
body: require('fs').readFileSync('benchmark-comment.md', 'utf8')
62+
});

0 commit comments

Comments
 (0)