Skip to content

Commit

Permalink
ci: add benching (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka authored Dec 22, 2024
1 parent 7a96084 commit edbf72e
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 0 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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: [ general ] # 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');
}
99 changes: 99 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ serde_json = '1.0.117'
slotmap = '1.0.7'
snafu = '0.8.5'
syn = '2.0.87'
tango-bench = "0.6.0"
tar = '0.4.41'
thiserror = '2.0.7'
tikv-jemallocator = '0.6.0'
Expand Down
6 changes: 6 additions & 0 deletions crates/geometry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ ordered-float = "4.5.0"

[dev-dependencies]
approx = { workspace = true }
rand = { workspace = true }
tango-bench = { workspace = true }

[lints]
workspace = true

[[bench]]
name = "general"
harness = false
Loading

0 comments on commit edbf72e

Please sign in to comment.