Skip to content

Commit bb1c42a

Browse files
committed
ci: add automated benchmark comparison workflow for pull requests
1 parent 5389158 commit bb1c42a

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: benchmark
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
permissions:
8+
pull-requests: write
9+
10+
jobs:
11+
benchmark:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Install Nix
15+
uses: DeterminateSystems/nix-installer-action@main
16+
17+
- name: Checkout PR branch
18+
uses: actions/checkout@v4
19+
with:
20+
path: "pr"
21+
22+
- name: Run benchmarks on PR
23+
run: |
24+
echo "Running benchmarks on PR commit ${{ github.event.pull_request.head.sha }}"
25+
cd pr
26+
nix run .#benchmark > ../pr.bench
27+
28+
- name: Checkout base branch
29+
uses: actions/checkout@v4
30+
with:
31+
ref: ${{ github.event.pull_request.base.sha }}
32+
path: "base"
33+
34+
- name: Run benchmarks on base
35+
run: |
36+
echo "Running benchmarks on base commit ${{ github.event.pull_request.base.sha }}"
37+
cd base
38+
nix run .#benchmark > ../base.bench
39+
40+
- name: Compare benchmarks
41+
id: compare
42+
run: |
43+
echo "Comparing benchmarks"
44+
nix-shell -p goperf --run "benchstat base.bench pr.bench" > comparison.txt
45+
echo "COMPARISON<<EOF" >> $GITHUB_OUTPUT
46+
echo '```' >> $GITHUB_OUTPUT
47+
cat comparison.txt >> $GITHUB_OUTPUT
48+
echo '```' >> $GITHUB_OUTPUT
49+
echo "EOF" >> $GITHUB_OUTPUT
50+
51+
- name: Post benchmark comment
52+
uses: peter-evans/create-or-update-comment@v2
53+
with:
54+
issue-number: ${{ github.event.pull_request.number }}
55+
body: |
56+
## Benchmark comparison
57+
58+
${{ steps.compare.outputs.COMPARISON }}

0 commit comments

Comments
 (0)