Skip to content

Commit

Permalink
Merge pull request #1122 from onekey-sec/ci-cargo-bench
Browse files Browse the repository at this point in the history
Fix and run `cargo bench` in CI
  • Loading branch information
qkaiser authored Feb 10, 2025
2 parents 107ee0a + e299bb6 commit 90dd7fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ jobs:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
run: cargo test
- name: Run benchmark
if: matrix.os == 'ubuntu-latest'
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
run: cargo bench -- --output-format bencher | tee bench.txt
- name: Store benchmark result
if: matrix.os == 'ubuntu-latest'
uses: benchmark-action/github-action-benchmark@v1
with:
tool: "cargo"
output-file-path: bench.txt
summary-always: true
comment-on-alert: true
github-token: ${{ secrets.GITHUB_TOKEN }}

build_linux_wheels:
name: Build wheels (linux)
Expand Down
5 changes: 4 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ crate-type = [
"cdylib", # for Python extension
"rlib", # for benchmarking
]
name = "unblob_rust"
name = "unblob"
# disable Rust nightly benchmark feature. We use criterion
# https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
bench = false

[dependencies]
log = "0.4.22"
Expand Down
4 changes: 2 additions & 2 deletions rust/benches/benches_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn shannon_entropy(c: &mut Criterion) {
BenchmarkId::from_parameter(sample_size),
&sample_size,
|b, &size| {
b.iter(|| unblob_native::math_tools::shannon_entropy(&sample[0..size]));
b.iter(|| unblob::math_tools::shannon_entropy(&sample[0..size]));
},
);
}
Expand All @@ -38,7 +38,7 @@ fn chi_square_probability(c: &mut Criterion) {
BenchmarkId::from_parameter(sample_size),
&sample_size,
|b, &size| {
b.iter(|| unblob_native::math_tools::chi_square_probability(&sample[0..size]));
b.iter(|| unblob::math_tools::chi_square_probability(&sample[0..size]));
},
);
}
Expand Down

0 comments on commit 90dd7fa

Please sign in to comment.