-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcustom_main.rs
More file actions
42 lines (37 loc) · 1.85 KB
/
Copy pathcustom_main.rs
File metadata and controls
42 lines (37 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/// Test bench for custom main patterns (COD-2324).
/// Verifies URI formatting when users bypass criterion_group!/criterion_main!.
use codspeed_criterion_compat::{criterion_group, BenchmarkId, Criterion};
fn bench_with_group(c: &mut Criterion) {
let mut group = c.benchmark_group("my_group");
group.bench_function("my_bench", |b| b.iter(|| 2 + 2));
group.bench_function(BenchmarkId::new("parameterized", 42), |b| b.iter(|| 2 + 2));
group.finish();
}
criterion_group!(benches, bench_with_group);
#[cfg(codspeed)]
fn main() {
// Pattern A: Using new_instrumented() but calling bench functions directly (not through criterion_group!)
// Since criterion_group! is bypassed, there is no macro context (group/function name),
// so the URI only contains the file, benchmark group, and benchmark name.
//
// Expected URIs:
// - crates/criterion_compat/benches/custom_main.rs::my_group::my_bench
// - crates/criterion_compat/benches/custom_main.rs::my_group::parameterized[42]
let mut criterion = Criterion::new_instrumented();
bench_with_group(&mut criterion);
// Pattern B: Calling through criterion_group!-generated function (should work correctly)
// The macro captures the criterion_group! name (`benches`) and the bench function name
// (`bench_with_group`), so both are part of the URI.
//
// Expected URIs:
// - crates/criterion_compat/benches/custom_main.rs::benches::bench_with_group::my_group::my_bench
// - crates/criterion_compat/benches/custom_main.rs::benches::bench_with_group::my_group::parameterized[42]
let mut criterion2 = Criterion::new_instrumented();
benches(&mut criterion2);
}
#[cfg(not(codspeed))]
fn main() {
// Without codspeed, just run through upstream criterion directly
let mut criterion = Criterion::default().configure_from_args();
bench_with_group(&mut criterion);
}