Skip to content

Commit e40765d

Browse files
committed
feat: add consts benchmark and missing items in __private
Signed-off-by: not-matthias <matthias@codspeed.io>
1 parent 5517175 commit e40765d

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

crates/divan_compat/benches/basic_example.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,38 @@ fn mut_borrow(bencher: Bencher) {
3232
});
3333
}
3434

35+
// Examples taken from the docs: https://docs.rs/divan/latest/divan/attr.bench.html#consts
36+
mod const_bench {
37+
const LEN: usize = 42;
38+
39+
const fn len() -> usize {
40+
4
41+
}
42+
43+
#[codspeed_divan_compat::bench(consts = [1000, LEN, len()])]
44+
fn init_array<const N: usize>() -> [i32; N] {
45+
let mut result = [0; N];
46+
47+
#[allow(clippy::needless_range_loop)]
48+
for i in 0..N {
49+
result[i] = divan::black_box(i as i32);
50+
}
51+
52+
result
53+
}
54+
55+
const SIZES: &[usize] = &[1, 10, LEN, len()];
56+
#[codspeed_divan_compat::bench(consts = SIZES)]
57+
fn bench_array1<const N: usize>() -> [i32; N] {
58+
init_array::<N>()
59+
}
60+
61+
#[codspeed_divan_compat::bench(consts = SIZES)]
62+
fn bench_array2<const N: usize>() -> [i32; N] {
63+
init_array::<N>()
64+
}
65+
}
66+
3567
fn main() {
3668
codspeed_divan_compat::main();
3769
}

crates/divan_compat/src/compat/entry/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::{
1616
BenchArgsRunner,
1717
};
1818

19-
pub use generic::{EntryType, GenericBenchEntry};
19+
pub use generic::{EntryConst, EntryType, GenericBenchEntry};
2020

2121
/// Benchmark entries generated by `#[divan::bench]`.
2222
///

crates/divan_compat/src/compat/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ pub mod __private {
44
pub use super::{
55
bench::{BenchArgs, BenchOptions},
66
entry::{
7-
BenchEntry, BenchEntryRunner, EntryList, EntryLocation, EntryMeta, EntryType,
8-
GenericBenchEntry, GroupEntry, BENCH_ENTRIES, GROUP_ENTRIES,
7+
BenchEntry, BenchEntryRunner, EntryConst, EntryList, EntryLocation, EntryMeta,
8+
EntryType, GenericBenchEntry, GroupEntry, BENCH_ENTRIES, GROUP_ENTRIES,
99
},
1010
};
1111

12-
pub use divan::__private::{Arg, ToStringHelper};
12+
pub use divan::__private::{shrink_array, Arg, ToStringHelper};
1313
}
1414

1515
mod bench;

0 commit comments

Comments
 (0)