diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000000..1e714f7e31 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,74 @@ +name: Benchmark + +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: read + +# Ensure scripts are run with pipefail. See: +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference +defaults: + run: + shell: bash + +jobs: + benchmark: + runs-on: ubuntu-latest + # runs-on: + # - 'self-hosted' + # - '1ES.Pool=TypeScript-1ES-GitHub-Large' + # - '1ES.ImageOverride=mariner-2.0' + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + submodules: true + filter: blob:none # https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/ + fetch-depth: 0 # Default is 1; need to set to 0 to get the benefits of blob:none. + - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 + - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 + with: + go-version: '>=1.23.0' + + - run: npm ci + + - name: Run benchmark + run: go test -run='^$' -bench=. -benchmem -count=10 ./... | tee new.txt + + - name: Switch to parent commit + run: git switch --detach HEAD^1 + + - run: npm ci + + - run: git submodule update --init --recursive + + - name: Run benchmark + run: go test -run='^$' -bench=. -benchmem -count=10 ./... | tee old.txt + + - run: go install golang.org/x/perf/cmd/benchstat@latest + + - name: Compare benchmarks + run: benchstat old.txt new.txt | tee benchstat.txt + + - uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 + with: + name: benchmarks + path: | + old.txt + new.txt + benchstat.txt + + - name: Create step summary + run: | + echo "See $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID for more info." + echo "# Benchmark Results" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + cat benchstat.txt >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY