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 | |
permissions: | |
contents: read | |
on: | |
push: | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: "The commit or branch to benchmark" | |
required: true | |
type: string | |
merge_group: | |
branches: | |
- main | |
# Make sure only a single benchmark job runs at a time for the main branch to prevent conflicts when | |
# pushing the benchmark data. | |
concurrency: | |
group: "benchmarking-${{inputs.ref}}" | |
cancel-in-progress: false | |
jobs: | |
bench: | |
name: "Benchmark ${{ matrix.name }}" | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 30 | |
strategy: | |
matrix: | |
include: | |
- name: linux-x86 | |
os: [benchmark, X64] | |
target: "x86_64-unknown-linux-gnu" | |
- name: macos-arm64 | |
os: [benchmark, ARM64, macOS] | |
target: "aarch64-apple-darwin" | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
persist-credentials: false | |
ref: "${{inputs.ref}}" | |
fetch-depth: 2 | |
- name: cargo build | |
run: | | |
. "$HOME/.cargo/env" | |
cargo build --target ${{matrix.target}} -p test-libz-rs-sys --release --examples | |
cd benchmarker && cargo build --release | |
- name: Fetch previous benchmark results | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.BENCH_DATA_DEPLOY_KEY }}" > ~/.ssh/id_ed25519 | |
chmod 600 ~/.ssh/id_ed25519 | |
chmod 700 ~/.ssh | |
git clone --depth 1 git@github.com:trifectatechfoundation/zlib-rs-bench.git | |
- name: Benchmark | |
run: | | |
cp target/${{matrix.target}}/release/examples/blogpost-compress . | |
cp target/${{matrix.target}}/release/examples/blogpost-uncompress . | |
benchmarker/target/release/benchmarker zlib_benchmarks.json zlib-rs-bench/metrics-${{matrix.name}}.json > bench_results.json | |
- name: Upload benchmark results to artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: "benchmark-results-${{matrix.name}}" | |
path: bench_results.json | |
- name: Upload benchmark results to bench repo | |
if: github.event_name == 'push' | |
run: | | |
cd zlib-rs-bench | |
git pull # ensure we have the latest state when another job pushed changes while benchmarking | |
cat ../bench_results.json >> metrics-${{matrix.name}}.json | |
git add . | |
git -c user.name="Perf bot" -c user.email=perf-bot@trifectatech.org commit --message 📈 | |
# git pull --rebase in case of a race condition with another job | |
git push origin main || (git -c user.name="Perf bot" -c user.email=perf-bot@trifectatech.org pull --rebase && git push origin main) |