@@ -9,7 +9,7 @@ use base64::{
99 write, Config ,
1010} ;
1111
12- use criterion:: { black_box, Bencher , Criterion , ParameterizedBenchmark , Throughput } ;
12+ use criterion:: { black_box, Bencher , Criterion , Throughput , BenchmarkId } ;
1313use rand:: { FromEntropy , Rng } ;
1414use std:: io:: { self , Read , Write } ;
1515
@@ -164,46 +164,53 @@ const BYTE_SIZES: [usize; 5] = [3, 50, 100, 500, 3 * 1024];
164164// keep the benchmark runtime reasonable.
165165const LARGE_BYTE_SIZES : [ usize ; 3 ] = [ 3 * 1024 * 1024 , 10 * 1024 * 1024 , 30 * 1024 * 1024 ] ;
166166
167- fn encode_benchmarks ( byte_sizes : & [ usize ] ) -> ParameterizedBenchmark < usize > {
168- ParameterizedBenchmark :: new ( "encode" , do_encode_bench, byte_sizes. iter ( ) . cloned ( ) )
167+ fn encode_benchmarks ( c : & mut Criterion , label : & str , byte_sizes : & [ usize ] ) {
168+ let mut group = c. benchmark_group ( label) ;
169+ group
169170 . warm_up_time ( std:: time:: Duration :: from_millis ( 500 ) )
170- . measurement_time ( std:: time:: Duration :: from_secs ( 3 ) )
171- . throughput ( |s| Throughput :: Bytes ( * s as u64 ) )
172- . with_function ( "encode_display" , do_encode_bench_display)
173- . with_function ( "encode_reuse_buf" , do_encode_bench_reuse_buf)
174- . with_function ( "encode_slice" , do_encode_bench_slice)
175- . with_function ( "encode_reuse_buf_stream" , do_encode_bench_stream)
176- . with_function ( "encode_string_stream" , do_encode_bench_string_stream)
177- . with_function (
178- "encode_string_reuse_buf_stream" ,
179- do_encode_bench_string_reuse_buf_stream,
180- )
181- }
171+ . measurement_time ( std:: time:: Duration :: from_secs ( 3 ) ) ;
172+
173+ for size in byte_sizes {
174+ group
175+ . throughput ( Throughput :: Bytes ( * size as u64 ) )
176+ . bench_with_input ( BenchmarkId :: new ( "encode" , size) , size, do_encode_bench)
177+ . bench_with_input ( BenchmarkId :: new ( "encode_display" , size) , size, do_encode_bench_display)
178+ . bench_with_input ( BenchmarkId :: new ( "encode_reuse_buf" , size) , size, do_encode_bench_reuse_buf)
179+ . bench_with_input ( BenchmarkId :: new ( "encode_slice" , size) , size, do_encode_bench_slice)
180+ . bench_with_input ( BenchmarkId :: new ( "encode_reuse_buf_stream" , size) , size, do_encode_bench_stream)
181+ . bench_with_input ( BenchmarkId :: new ( "encode_string_stream" , size) , size, do_encode_bench_string_stream)
182+ . bench_with_input (
183+ BenchmarkId :: new ( "encode_string_reuse_buf_stream" , size) ,
184+ size,
185+ do_encode_bench_string_reuse_buf_stream,
186+ ) ;
187+ }
182188
183- fn decode_benchmarks ( byte_sizes : & [ usize ] ) -> ParameterizedBenchmark < usize > {
184- ParameterizedBenchmark :: new ( "decode" , do_decode_bench, byte_sizes. iter ( ) . cloned ( ) )
185- . warm_up_time ( std:: time:: Duration :: from_millis ( 500 ) )
186- . measurement_time ( std:: time:: Duration :: from_secs ( 3 ) )
187- . throughput ( |s| Throughput :: Bytes ( * s as u64 ) )
188- . with_function ( "decode_reuse_buf" , do_decode_bench_reuse_buf)
189- . with_function ( "decode_slice" , do_decode_bench_slice)
190- . with_function ( "decode_stream" , do_decode_bench_stream)
189+ group. finish ( ) ;
191190}
192191
193- fn bench ( c : & mut Criterion ) {
194- c. bench ( "bench_small_input" , encode_benchmarks ( & BYTE_SIZES [ ..] ) ) ;
195-
196- c. bench (
197- "bench_large_input" ,
198- encode_benchmarks ( & LARGE_BYTE_SIZES [ ..] ) . sample_size ( 10 ) ,
199- ) ;
192+ fn decode_benchmarks ( c : & mut Criterion , label : & str , byte_sizes : & [ usize ] ) {
193+ let mut group = c. benchmark_group ( label) ;
194+
195+ for size in byte_sizes {
196+ group
197+ . warm_up_time ( std:: time:: Duration :: from_millis ( 500 ) )
198+ . measurement_time ( std:: time:: Duration :: from_secs ( 3 ) )
199+ . throughput ( Throughput :: Bytes ( * size as u64 ) )
200+ . bench_with_input ( BenchmarkId :: new ( "decode" , size) , size, do_decode_bench)
201+ . bench_with_input ( BenchmarkId :: new ( "decode_reuse_buf" , size) , size, do_decode_bench_reuse_buf)
202+ . bench_with_input ( BenchmarkId :: new ( "decode_slice" , size) , size, do_decode_bench_slice)
203+ . bench_with_input ( BenchmarkId :: new ( "decode_stream" , size) , size, do_decode_bench_stream) ;
204+ }
200205
201- c. bench ( "bench_small_input" , decode_benchmarks ( & BYTE_SIZES [ ..] ) ) ;
206+ group. finish ( ) ;
207+ }
202208
203- c. bench (
204- "bench_large_input" ,
205- decode_benchmarks ( & LARGE_BYTE_SIZES [ ..] ) . sample_size ( 10 ) ,
206- ) ;
209+ fn bench ( c : & mut Criterion ) {
210+ encode_benchmarks ( c, "encode_small_input" , & BYTE_SIZES [ ..] ) ;
211+ encode_benchmarks ( c, "encode_large_input" , & LARGE_BYTE_SIZES [ ..] ) ;
212+ decode_benchmarks ( c, "decode_small_input" , & BYTE_SIZES [ ..] ) ;
213+ decode_benchmarks ( c, "decode_large_input" , & LARGE_BYTE_SIZES [ ..] ) ;
207214}
208215
209216criterion_group ! ( benches, bench) ;
0 commit comments