feat: some optimize #23
Workflow file for this run
This file contains 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 | |
paths-ignore: | |
- "**/*.md" | |
pull_request: | |
paths-ignore: | |
- "**/*.md" | |
permissions: | |
contents: write | |
pull-requests: write | |
deployments: write | |
jobs: | |
benchmark: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # to be able to retrieve the last commit | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: "stable" | |
- name: Run Benchmark | |
run: set -o pipefail; go test ./... -benchmem -run=^$ -bench . | tee output.txt | |
# NOTE: Benchmarks could change with different CPU types | |
- name: Get GitHub Runner System Information | |
uses: kenchan0130/[email protected] | |
id: system-info | |
- name: Get master branch SHA | |
id: get-master-branch-sha | |
run: | | |
SHA="$(git rev-parse origin/master)" | |
echo "sha=$SHA" >> $GITHUB_OUTPUT | |
- name: Get Benchmark Results from master branch | |
id: cache | |
uses: actions/cache/restore@v4 | |
with: | |
path: ./cache | |
key: ${{ steps.get-master-branch-sha.outputs.sha }}-${{ runner.os }}-${{ steps.system-info.outputs.cpu-model }}-benchmark | |
# This will only run if we have Benchmark Results from master branch | |
- name: Compare PR Benchmark Results with master branch | |
uses: benchmark-action/[email protected] | |
if: steps.cache.outputs.cache-hit == 'true' | |
with: | |
tool: 'go' | |
output-file-path: output.txt | |
external-data-json-path: ./cache/benchmark-data.json | |
# Do not save the data (This allows comparing benchmarks) | |
save-data-file: false | |
fail-on-alert: true | |
# Comment on the PR if the branch is not a fork | |
comment-on-alert: ${{ github.event.pull_request.head.repo.fork == false }} | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
summary-always: true | |
alert-threshold: "150%" | |
- name: Store Benchmark Results for master branch | |
uses: benchmark-action/[email protected] | |
if: ${{ github.ref_name == 'master' }} | |
with: | |
tool: 'go' | |
output-file-path: output.txt | |
external-data-json-path: ./cache/benchmark-data.json | |
# Save the data to external file (cache) | |
save-data-file: true | |
fail-on-alert: false | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
summary-always: true | |
alert-threshold: "150%" | |
- name: Publish Benchmark Results to GitHub Pages | |
uses: benchmark-action/github-action-benchmark@v1 | |
if: ${{ github.ref_name == 'master' }} | |
with: | |
tool: 'go' | |
output-file-path: output.txt | |
benchmark-data-dir-path: "benchmarks" | |
fail-on-alert: false | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
comment-on-alert: true | |
summary-always: true | |
# Save the data to external file (GitHub Pages) | |
save-data-file: true | |
alert-threshold: "150%" | |
auto-push: true | |
- name: Update Benchmark Results cache | |
uses: actions/cache/save@v4 | |
if: ${{ github.ref_name == 'master' }} | |
with: | |
path: ./cache | |
key: ${{ steps.get-master-branch-sha.outputs.sha }}-${{ runner.os }}-${{ steps.system-info.outputs.cpu-model }}-benchmark |