1- //! Benchmarks for DogStatsD payload generation.
1+ //! Benchmarks for ` DogStatsD` payload generation.
22
3- use criterion:: { BenchmarkId , Criterion , Throughput , criterion_group, criterion_main} ;
3+ use criterion:: { BatchSize , BenchmarkId , Criterion , Throughput , criterion_group, criterion_main} ;
44use lading_payload:: { Serialize , dogstatsd} ;
55use rand:: { SeedableRng , rngs:: SmallRng } ;
66use std:: time:: Duration ;
@@ -12,24 +12,28 @@ fn dogstatsd_setup(c: &mut Criterion) {
1212 b. iter ( || {
1313 let mut rng = SmallRng :: seed_from_u64 ( 19_690_716 ) ;
1414 let _dd = dogstatsd:: DogStatsD :: default ( & mut rng) ;
15- } )
15+ } ) ;
1616 } ) ;
1717}
1818
19- fn dogstatsd_all ( c : & mut Criterion ) {
20- let mut group = c. benchmark_group ( "dogstatsd_all " ) ;
19+ fn dogstatsd_throughput ( c : & mut Criterion ) {
20+ let mut group = c. benchmark_group ( "dogstatsd_throughput " ) ;
2121 for size in & [ MIB , 10 * MIB , 100 * MIB , 1_000 * MIB ] {
2222 group. throughput ( Throughput :: Bytes ( * size as u64 ) ) ;
2323 group. bench_with_input ( BenchmarkId :: from_parameter ( size) , size, |b, & size| {
24- b. iter ( || {
25- let mut rng = SmallRng :: seed_from_u64 ( 19_690_716 ) ;
26- let mut dd =
27- dogstatsd:: DogStatsD :: default ( & mut rng) . expect ( "failed to create DogStatsD" ) ;
28- let mut writer = Vec :: with_capacity ( size) ;
29-
30- dd. to_bytes ( rng, size, & mut writer)
31- . expect ( "failed to convert to bytes" ) ;
32- } ) ;
24+ b. iter_batched (
25+ || {
26+ let mut rng = SmallRng :: seed_from_u64 ( 19_690_716 ) ;
27+ let dd = dogstatsd:: DogStatsD :: default ( & mut rng)
28+ . expect ( "failed to create DogStatsD" ) ;
29+ ( rng, dd, Vec :: with_capacity ( size) )
30+ } ,
31+ |( rng, mut dd, mut writer) | {
32+ dd. to_bytes ( rng, size, & mut writer)
33+ . expect ( "failed to convert to bytes" ) ;
34+ } ,
35+ BatchSize :: PerIteration ,
36+ ) ;
3337 } ) ;
3438 }
3539 group. finish ( ) ;
@@ -38,7 +42,7 @@ fn dogstatsd_all(c: &mut Criterion) {
3842criterion_group ! (
3943 name = setup_benches;
4044 config = Criterion :: default ( )
41- . measurement_time( Duration :: from_secs( 10 ) )
45+ . measurement_time( Duration :: from_secs( 5 ) )
4246 . warm_up_time( Duration :: from_secs( 1 ) ) ;
4347 targets = dogstatsd_setup,
4448) ;
@@ -48,7 +52,7 @@ criterion_group!(
4852 config = Criterion :: default ( )
4953 . measurement_time( Duration :: from_secs( 30 ) )
5054 . warm_up_time( Duration :: from_secs( 1 ) ) ;
51- targets = dogstatsd_all ,
55+ targets = dogstatsd_throughput ,
5256) ;
5357
5458criterion_main ! ( setup_benches, throughput_benches) ;
0 commit comments