-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathrepro_custom_main.rs
More file actions
30 lines (25 loc) · 1.16 KB
/
repro_custom_main.rs
File metadata and controls
30 lines (25 loc) · 1.16 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
/// Reproducer for COD-2324: URI formatting issues when users bypass criterion_group!/criterion_main!
/// and use a custom main function (like the rtmalloc project does).
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!)
let mut criterion = Criterion::new_instrumented();
bench_with_group(&mut criterion);
// Pattern B: Calling through criterion_group!-generated function (should work correctly)
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);
}