1
+ extern crate criterion;
2
+
3
+ use std:: hint:: black_box;
4
+ use std:: io:: Read ;
5
+
6
+ use criterion:: { criterion_group, criterion_main, Criterion , Throughput } ;
7
+ use miniz_oxide:: deflate:: { compress_to_vec, compress_to_vec_zlib} ;
8
+ use miniz_oxide:: inflate:: { decompress_to_vec, decompress_to_vec_zlib, TINFLStatus } ;
9
+
10
+ fn get_test_file_data ( name : & str ) -> Vec < u8 > {
11
+ use std:: fs:: File ;
12
+ let mut input = Vec :: new ( ) ;
13
+ let mut f = File :: open ( name) . unwrap ( ) ;
14
+
15
+ f. read_to_end ( & mut input) . unwrap ( ) ;
16
+ input
17
+ }
18
+
19
+ fn get_test_data ( ) -> Vec < u8 > {
20
+ use std:: env;
21
+ let path = env:: var ( "TEST_FILE" ) . unwrap_or_else ( |_| "../miniz/miniz.c" . to_string ( ) ) ;
22
+ get_test_file_data ( & path)
23
+ }
24
+
25
+ fn bench_inflate ( c : & mut Criterion ) {
26
+ let data = get_test_data ( ) ;
27
+ let compressed= compress_to_vec ( & data, 6 ) ;
28
+ c. bench_function ( "inflate" , |b| b. iter ( || decompress_to_vec ( black_box ( & compressed) ) ) ) ;
29
+ let compressed_zlib = compress_to_vec_zlib ( & data, 6 ) ;
30
+ c. bench_function ( "inflate_zlib" , |b| b. iter ( || decompress_to_vec_zlib ( black_box ( & compressed_zlib) ) ) ) ;
31
+ }
32
+
33
+ fn bench_deflate ( c : & mut Criterion ) {
34
+ let data = get_test_data ( ) ;
35
+ c. bench_function ( "deflate_l6" , |b| b. iter ( || compress_to_vec ( black_box ( & data) , 6 ) ) ) ;
36
+ c. bench_function ( "deflate_zlib_l6" , |b| b. iter ( || compress_to_vec_zlib ( black_box ( & data) , 6 ) ) ) ;
37
+ }
38
+
39
+ criterion_group ! ( benches, bench_inflate, bench_deflate) ;
40
+ criterion_main ! ( benches) ;
0 commit comments