Skip to content

add tests & benchmarks #2

add tests & benchmarks

add tests & benchmarks #2

Workflow file for this run

name: Benchmark
on:
push:
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go environment
uses: actions/setup-go@v4
with:
go-version: 1.25.1
- name: Install benchstat
run: go install golang.org/x/perf/cmd/benchstat@latest
- name: Run benchmarks on base branch
if: github.event_name == 'pull_request'
run: |
git checkout ${{ github.event.pull_request.base.sha }}
go mod tidy
go test -bench . -count 7 -benchmem > base-bench.txt
git checkout ${{ github.event.pull_request.head.sha }}
- name: Run benchmarks on current commit
run: |
go mod tidy
go test -bench . -count 7 -benchmem > current-bench.txt
- name: Compare benchmarks
if: github.event_name == 'pull_request'
run: |
cat > benchmark-comment.md << EOF
## Benchmark Results
```
$(benchstat base-bench.txt current-bench.txt || echo "No significant differences found.")
```
EOF
- name: Comment PR with benchmark results
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const comment = fs.readFileSync('benchmark-comment.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Check for significant regressions
if: github.event_name == 'pull_request'
run: |
# Parse benchstat output for significant regressions
if benchstat base-bench.txt current-bench.txt | grep -E '\+[0-9]+\.[0-9]+%.*p=0\.[0-9]+' | grep -v '~'; then
echo "::warning::Potential performance regression detected. Review benchmark results."
fi