Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add a benchmark workflow #176

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Benchstat

on:
pull_request:
branches: [ master ]

permissions: # added using https://github.com/step-security/secure-workflows
contents: read

jobs:

bench:
name: Performance regression check
runs-on: ubuntu-latest
steps:
- name: Checkout (new)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you cloning twice?

You could clone once and switch branches.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only fetches a single commit by default. If I wanted to clone once and switch, I'd have to fetch all history for all branches and tags. This seems simpler/cleaner.

uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: '${{ github.workspace }}/go.mod'

- name: Get dependencies
run: go mod download

- name: Benchmark against GITHUB_BASE_REF
run: |
go install golang.org/x/perf/cmd/benchstat@latest
echo "New Commit:"
git log -1 --format="%H"
go test -bench=. -benchmem -benchtime=100ms -count=10 ./... > /tmp/new.txt
git reset --hard HEAD
git checkout $GITHUB_BASE_REF
echo "Base Commit:"
git log -1 --format="%H"
go test -bench=. -benchmem -benchtime=100ms -count=10 ./... > /tmp/old.txt
$GOBIN/benchstat /tmp/old.txt /tmp/new.txt
Loading