1- use codspeed_criterion_compat:: { criterion_group, criterion_main, Bencher , BenchmarkId , Criterion } ;
1+ use codspeed_criterion_compat:: {
2+ criterion_group, criterion_main, Bencher , BenchmarkGroup , BenchmarkId , Criterion ,
3+ } ;
4+ use criterion:: measurement:: WallTime ;
25
36fn bench ( c : & mut Criterion ) {
47 // Setup (construct data, allocate memory, etc)
@@ -31,6 +34,25 @@ fn bench_with_explicit_lifetime(c: &mut Criterion) {
3134 ) ;
3235}
3336
37+ #[ cfg( codspeed) ]
38+ fn bench_using_group_without_explicit_measurement ( c : & mut Criterion ) {
39+ let mut group = c. benchmark_group ( "group" ) ;
40+ fn using_group ( g : & mut BenchmarkGroup ) {
41+ g. bench_function ( "bench_without_explicit_measurement" , |b| b. iter ( || 2 + 2 ) ) ;
42+ }
43+ using_group ( & mut group) ;
44+ group. finish ( ) ;
45+ }
46+
47+ fn bench_using_group_with_explicit_measurement ( c : & mut Criterion ) {
48+ let mut group = c. benchmark_group ( "group" ) ;
49+ fn using_group ( g : & mut BenchmarkGroup < ' _ , WallTime > ) {
50+ g. bench_function ( "bench_explicit_measurement" , |b| b. iter ( || 2 + 2 ) ) ;
51+ }
52+ using_group ( & mut group) ;
53+ group. finish ( ) ;
54+ }
55+
3456mod nested {
3557 use super :: * ;
3658 pub fn bench ( c : & mut Criterion ) {
@@ -48,5 +70,22 @@ mod nested {
4870 }
4971}
5072
51- criterion_group ! ( benches, bench, bench_with_explicit_lifetime, nested:: bench) ;
73+ criterion_group ! (
74+ benches,
75+ bench,
76+ bench_with_explicit_lifetime,
77+ nested:: bench,
78+ bench_using_group_with_explicit_measurement,
79+ ) ;
80+
81+ #[ cfg( not( codspeed) ) ]
5282criterion_main ! ( benches) ;
83+
84+ #[ cfg( codspeed) ]
85+ criterion_group ! (
86+ only_codspeed,
87+ bench_using_group_without_explicit_measurement
88+ ) ;
89+
90+ #[ cfg( codspeed) ]
91+ criterion_main ! ( benches, only_codspeed) ;
0 commit comments