Skip to content

Commit

Permalink
cicd: benchmarking via GH actions
Browse files Browse the repository at this point in the history
Benchmark the current HEAD as well as the master branch and compare
performance.
  • Loading branch information
Peter Van Bouwel committed Jan 28, 2025
1 parent eccf964 commit 2521bab
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
52 changes: 52 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# As inspired by https://dev.to/vearutop/continuous-benchmarking-with-go-and-github-actions-41ok
name: bench
on:
pull_request:
env:
GO111MODULE: "on"
jobs:
bench:
strategy:
matrix:
go-version: [ 1.22.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/go/pkg
key: ${{ runner.os }}-go-pkg-${{ hashFiles('**/go.mod') }}
- uses: actions/cache@v2
with:
path: ~/go/bin/benchstat
key: ${{ runner.os }}-benchstat
- uses: actions/cache@v2
with:
path: |
cmd/bench-main.txt
# Using base sha for PR or new commit hash for main push in benchmark result key.
key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
- name: Benchmark
run: |
make setup-test-dependencies
make start-test-s3-servers
REF_NAME=${GITHUB_REF##*/} make bench-current
make bench-main
echo "\n\n\n"
export SCRIPT_OUTPUT="$(make bench-report)"
- name: Add benchmark report to PR
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${{env.SCRIPT_OUTPUT}}`
})
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

testing/venv/**
testing/**.err
testing/**.log
testing/**.log

cmd/bench-*.txt
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
BENCH_COUNT ?= 10
REF_NAME ?= $(shell git symbolic-ref HEAD --short | tr / - 2>/dev/null)


build-container:
podman build -t fakes3pp -f Dockerfile .

Expand All @@ -19,3 +23,18 @@ start-test-s3-servers:

stop-test-s3-servers:
for pid in `ps -ef | grep testing/venv/moto/bin/python3 | grep -v grep | awk '{print $$2}'`; do kill "$${pid}"; done

bench-dependencies:
@test -s $(GOPATH)/bin/benchstat || go install golang.org/x/perf/cmd/benchstat@latest

bench-main: bench-dependencies
git branch --show-current | tr -d '\n' > cmd/bench-current_branch.txt
git checkout main
cd cmd && go test -bench=. -benchtime=5s -run "FakeS3Proxy" -benchmem -count=$(BENCH_COUNT) | tee bench-main.txt && cd ..
git checkout "$(shell cat cmd/bench-current_branch.txt)"

bench-current: bench-dependencies
cd cmd && go test -bench=. -benchtime=5s -run "FakeS3Proxy" -benchmem -count=$(BENCH_COUNT) | tee bench-$(REF_NAME).txt && cd ..

bench-report: bench-dependencies
benchstat cmd/bench-main.txt cmd/bench-$(REF_NAME).txt | tee cmd/bench-$(REF_NAME)-master-report.txt

0 comments on commit 2521bab

Please sign in to comment.