ci: add benching #308
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: Bench | |
on: | |
pull_request: | |
branches: [ main ] | |
push: | |
branches: [ main ] | |
env: | |
RUST_NIGHTLY_TOOLCHAIN: nightly-2024-12-18 | |
RUSTFLAGS: -Clinker=/usr/bin/clang -Clink-arg=--ld-path=/usr/local/bin/mold -Ctarget-cpu=native -Zshare-generics=y -Zthreads=0 | |
jobs: | |
export: | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
benchmark: [ side_by_side, other_benchmark ] # Add your benchmarks here | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: rui314/setup-mold@v1 | |
- name: Install cargo-export | |
uses: taiki-e/install-action@v2 | |
with: | |
tool: cargo-export | |
- uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ env.RUST_NIGHTLY_TOOLCHAIN }} | |
- uses: Swatinem/rust-cache@v2 | |
- name: Run cargo export | |
run: cargo export target/benchmarks -- bench --bench=${{ matrix.benchmark }} | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: bench_${{ matrix.benchmark }} | |
path: target/benchmarks/${{ matrix.benchmark }} | |
compare: | |
if: github.event_name == 'pull_request' && github.base_ref == 'main' | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
benchmark: [ general ] # Add your benchmarks here | |
permissions: | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download Artifact | |
id: download | |
uses: dawidd6/action-download-artifact@v3 | |
continue-on-error: true | |
with: | |
commit: ${{ github.event.pull_request.base.sha }} | |
name: bench_${{ matrix.benchmark }} | |
path: /tmp/bench/ | |
- uses: rui314/setup-mold@v1 | |
- uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ env.RUST_NIGHTLY_TOOLCHAIN }} | |
- uses: Swatinem/rust-cache@v2 | |
- name: Run cargo bench | |
if: steps.download.outcome == 'success' | |
run: cargo bench --bench=${{ matrix.benchmark }} -- compare /tmp/bench/${{ matrix.benchmark }} > bench_output_${{ matrix.benchmark }}.txt | |
- name: remove /tmp/bench | |
if: steps.download.outcome == 'success' | |
run: rm -rf /tmp/bench | |
- name: Post benchmark results as PR comment | |
if: steps.download.outcome == 'success' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const path = `bench_output_${{ matrix.benchmark }}.txt`; | |
const output = fs.readFileSync(path, 'utf8'); | |
const originalSha = context.payload.pull_request.base.sha; | |
const issue_number = context.issue.number; | |
if(issue_number) { | |
const comment = { | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: `### Benchmark Results for ${{ matrix.benchmark }}\n\`\`\`\n${output}\`\`\`\n\nComparing to ${originalSha}`, | |
}; | |
await github.rest.issues.createComment(comment); | |
} else { | |
console.log('This action must be run in the context of a pull request'); | |
} |