diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 000000000..ba1051aaf --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,34 @@ +name: go benchmarks +on: + push: + branches: + - main + pull_request: + +jobs: + benchmark: + name: benchmark regression check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - name: Run benchmark + run: make bench.txt + - name: Download previous benchmark data + uses: actions/cache@v4 + with: + path: ./cache + key: ${{ runner.os }}-benchmark + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + tool: 'go' + output-file-path: bench.txt + external-data-json-path: ./cache/benchmark-data.json + fail-on-alert: true + comment-on-alert: true + comment-always: true + github-token: ${{ secrets.GITHUB_TOKEN }} + alert-threshold: "200%" diff --git a/.gitignore b/.gitignore index 9dc534327..2aae110ef 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ report.xml *.out .netlify docs/.hugo_build.lock +bench.txt diff --git a/Makefile b/Makefile index 96cad9e98..1b54898e7 100644 --- a/Makefile +++ b/Makefile @@ -159,6 +159,9 @@ test: $(GO) test -race -coverprofile=c.out ./... endif +bench.txt: go.mod go.sum $(GO_FILES) + $(GO) test -benchmem -run=xxx -bench . ./... | tee $@ + .SECONDEXPANSION: testbin/%.test.exe: $$(shell $$(GO) list -f '{{.Dir}}' $$(subst testbin/,,$$(subst .test.exe,,$$@))) @GOOS=windows GOARCH=amd64 $(GO) test -c -o $@ $<