Skip to content

Commit 9193076

Browse files
committed
benches: Port factor benchmarks from Criterion to Divan
Replace Criterion with Divan to align with all other benchmarks in the codebase (22 packages use Divan, only factor used Criterion). Eliminates the html_reports warning and consolidates on a single benchmarking framework across the project.
1 parent a6976e1 commit 9193076

File tree

3 files changed

+24
-161
lines changed

3 files changed

+24
-161
lines changed

Cargo.lock

Lines changed: 7 additions & 142 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/benches/factor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ publish = false
1010

1111
[dev-dependencies]
1212
array-init = "2.0.0"
13-
criterion = "0.6.0"
13+
divan = { workspace = true }
1414
rand = "0.9.1"
1515
rand_chacha = "0.9.0"
1616
num-prime = "0.4.4"

tests/benches/factor/benches/table.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
// spell-checker:ignore funcs
77

88
use array_init::array_init;
9-
use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
9+
use divan::Bencher;
1010

11-
fn table(c: &mut Criterion) {
11+
fn main() {
12+
divan::main();
13+
}
14+
15+
#[divan::bench()]
16+
fn factor_table(bencher: Bencher) {
1217
#[cfg(target_os = "linux")]
1318
check_personality();
1419

@@ -22,21 +27,17 @@ fn table(c: &mut Criterion) {
2227
let mut rng = ChaCha8Rng::seed_from_u64(SEED);
2328

2429
std::iter::repeat_with(move || array_init::<_, _, INPUT_SIZE>(|_| rng.next_u64()))
30+
.take(10)
31+
.collect::<Vec<_>>()
2532
};
2633

27-
let mut group = c.benchmark_group("table");
28-
group.throughput(Throughput::Elements(INPUT_SIZE as _));
29-
for a in inputs.take(10) {
30-
let a_str = format!("{a:?}");
31-
group.bench_with_input(BenchmarkId::new("factor", &a_str), &a, |b, &a| {
32-
b.iter(|| {
33-
for n in a {
34-
let _r = num_prime::nt_funcs::factors(n, None);
35-
}
36-
});
37-
});
38-
}
39-
group.finish();
34+
bencher.bench(|| {
35+
for a in &inputs {
36+
for n in a {
37+
divan::black_box(num_prime::nt_funcs::factors(*n, None));
38+
}
39+
}
40+
});
4041
}
4142

4243
#[cfg(target_os = "linux")]
@@ -59,6 +60,3 @@ fn check_personality() {
5960
);
6061
}
6162
}
62-
63-
criterion_group!(benches, table);
64-
criterion_main!(benches);

0 commit comments

Comments
 (0)