Skip to content

Commit 90dd7fa

Browse files
authored
Merge pull request #1122 from onekey-sec/ci-cargo-bench
Fix and run `cargo bench` in CI
2 parents 107ee0a + e299bb6 commit 90dd7fa

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

.github/workflows/CI.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ jobs:
103103
SCCACHE_GHA_ENABLED: "true"
104104
RUSTC_WRAPPER: "sccache"
105105
run: cargo test
106+
- name: Run benchmark
107+
if: matrix.os == 'ubuntu-latest'
108+
env:
109+
SCCACHE_GHA_ENABLED: "true"
110+
RUSTC_WRAPPER: "sccache"
111+
run: cargo bench -- --output-format bencher | tee bench.txt
112+
- name: Store benchmark result
113+
if: matrix.os == 'ubuntu-latest'
114+
uses: benchmark-action/github-action-benchmark@v1
115+
with:
116+
tool: "cargo"
117+
output-file-path: bench.txt
118+
summary-always: true
119+
comment-on-alert: true
120+
github-token: ${{ secrets.GITHUB_TOKEN }}
106121

107122
build_linux_wheels:
108123
name: Build wheels (linux)

rust/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ crate-type = [
1111
"cdylib", # for Python extension
1212
"rlib", # for benchmarking
1313
]
14-
name = "unblob_rust"
14+
name = "unblob"
15+
# disable Rust nightly benchmark feature. We use criterion
16+
# https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
17+
bench = false
1518

1619
[dependencies]
1720
log = "0.4.22"

rust/benches/benches_main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn shannon_entropy(c: &mut Criterion) {
1919
BenchmarkId::from_parameter(sample_size),
2020
&sample_size,
2121
|b, &size| {
22-
b.iter(|| unblob_native::math_tools::shannon_entropy(&sample[0..size]));
22+
b.iter(|| unblob::math_tools::shannon_entropy(&sample[0..size]));
2323
},
2424
);
2525
}
@@ -38,7 +38,7 @@ fn chi_square_probability(c: &mut Criterion) {
3838
BenchmarkId::from_parameter(sample_size),
3939
&sample_size,
4040
|b, &size| {
41-
b.iter(|| unblob_native::math_tools::chi_square_probability(&sample[0..size]));
41+
b.iter(|| unblob::math_tools::chi_square_probability(&sample[0..size]));
4242
},
4343
);
4444
}

0 commit comments

Comments
 (0)