Port cadencefmt #8478
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Benchmark | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - 'feature/**' | |
| - 'v**' | |
| pull_request: | |
| branches: | |
| - master | |
| - 'feature/**' | |
| - 'v**' | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} | |
| cancel-in-progress: true | |
| jobs: | |
| benchmark: | |
| name: Performance regression check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Detect changed components | |
| uses: dorny/paths-filter@v3 | |
| id: changes | |
| with: | |
| filters: | | |
| encoding: | |
| - 'encoding/**' | |
| parser: | |
| - 'parser/**' | |
| sema: | |
| - 'sema/**' | |
| bbq: | |
| - 'bbq/**' | |
| - name: Set benchmark settings | |
| # reducing repetition and time will speed up execution, | |
| # but will be more inaccurate at detecting change | |
| run: | | |
| echo "benchmark_repetitions=2" >> "$GITHUB_OUTPUT" | |
| echo "benchmark_time=2s" >> "$GITHUB_OUTPUT" | |
| id: settings | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Run unconditional benchmarks, on current branch | |
| run: make bench-common BENCH_REPS=${{ steps.settings.outputs.benchmark_repetitions }} BENCH_TIME=${{ steps.settings.outputs.benchmark_time }} | tee new.txt | |
| - name: Run benchmarks for changed components, on current branch | |
| run: | | |
| for component in ${{ join(fromJSON(steps.changes.outputs.changes), ' ') }}; do | |
| make bench BENCH_PKGS=./$component/... BENCH_REPS=${{ steps.settings.outputs.benchmark_repetitions }} BENCH_TIME=${{ steps.settings.outputs.benchmark_time }} | tee -a new.txt | |
| done | |
| - name: Checkout base branch | |
| run: git checkout ${{ github.event.pull_request.base.sha }} | |
| - name: Run unconditional benchmarks, on base branch | |
| run: make bench-common BENCH_REPS=${{ steps.settings.outputs.benchmark_repetitions }} BENCH_TIME=${{ steps.settings.outputs.benchmark_time }} | tee old.txt | |
| - name: Run benchmarks for changed components, on base branch | |
| run: | | |
| for component in ${{ join(fromJSON(steps.changes.outputs.changes), ' ') }}; do | |
| make bench BENCH_PKGS=./$component/... BENCH_REPS=${{ steps.settings.outputs.benchmark_repetitions }} BENCH_TIME=${{ steps.settings.outputs.benchmark_time }} | tee -a old.txt | |
| done | |
| # see https://trstringer.com/github-actions-multiline-strings/ to see why this part is complex | |
| - name: Use benchstat for comparison | |
| run: | | |
| export PATH=$PATH:$(go env GOPATH)/bin | |
| make install-benchstat | |
| echo "BENCHSTAT<<EOF" >> $GITHUB_ENV | |
| echo "$(benchstat -html -sort name old.txt new.txt | sed '/<title/,/<\/style>/d' | sed 's/<!doctype html>//g')" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| - name: Find existing comment on PR | |
| uses: peter-evans/find-comment@v1 | |
| id: fc | |
| with: | |
| issue-number: ${{ github.event.pull_request.number }} | |
| comment-author: "github-actions[bot]" | |
| body-includes: "## [Benchstat](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat) comparison" | |
| - name: Create or update comment | |
| uses: peter-evans/create-or-update-comment@v1 | |
| with: | |
| comment-id: ${{ steps.fc.outputs.comment-id }} | |
| issue-number: ${{ github.event.pull_request.number }} | |
| body: | | |
| ## [Benchstat](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat) comparison | |
| - Base branch: ${{ github.event.pull_request.base.label }} | |
| - Base commit: ${{ github.event.pull_request.base.sha }} | |
| <details> | |
| <summary>Results</summary> | |
| <p> | |
| ${{ env.BENCHSTAT }} | |
| </p> | |
| </details> | |
| edit-mode: replace |