Skip to content

Commit b1f6a70

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 b1f6a70

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

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: 18 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,19 @@ 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({
38+
let _r = num_prime::nt_funcs::factors(*n, None);
39+
});
40+
}
41+
}
42+
});
4043
}
4144

4245
#[cfg(target_os = "linux")]
@@ -59,6 +62,3 @@ fn check_personality() {
5962
);
6063
}
6164
}
62-
63-
criterion_group!(benches, table);
64-
criterion_main!(benches);

0 commit comments

Comments
 (0)