File tree Expand file tree Collapse file tree 2 files changed +44
-16
lines changed Expand file tree Collapse file tree 2 files changed +44
-16
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ rand_xorshift = "0.2.0"
20
20
rand = " 0.7.3"
21
21
criterion = " 0.3"
22
22
serde_json = " 1.0"
23
+ gperftools = " 0.2.0"
23
24
24
25
[features ]
25
26
json = []
Original file line number Diff line number Diff line change 3
3
4
4
mod examples;
5
5
6
+ use std:: fs;
7
+ use std:: path:: Path ;
6
8
use criterion:: { black_box, criterion_group, criterion_main, Criterion } ;
7
9
use examples:: { example1, example2} ;
8
10
use fvm_ipld_bitfield:: BitField ;
11
+ use gperftools:: profiler:: PROFILER ;
12
+
13
+ struct Profiler ;
14
+
15
+ impl criterion:: profiler:: Profiler for Profiler {
16
+ fn start_profiling ( & mut self , benchmark_id : & str , benchmark_dir : & Path ) {
17
+ fs:: create_dir_all ( benchmark_dir) . unwrap ( ) ;
18
+ let bench_file =benchmark_id. to_owned ( ) + ".prof" ;
19
+ let bench_path = benchmark_dir. join ( bench_file) ;
20
+ let bench_str = bench_path. to_str ( ) . unwrap ( ) ;
21
+
22
+ PROFILER . lock ( ) . unwrap ( ) . start ( bench_str) . unwrap ( ) ;
23
+ }
24
+
25
+ fn stop_profiling ( & mut self , _: & str , _: & Path ) {
26
+ PROFILER . lock ( ) . unwrap ( ) . stop ( ) . unwrap ( ) ;
27
+ }
28
+ }
29
+
30
+ fn profiled ( ) -> Criterion {
31
+ Criterion :: default ( ) . with_profiler ( Profiler { } )
32
+ }
33
+
9
34
10
35
fn len ( c : & mut Criterion ) {
11
36
let bf = example1 ( ) ;
@@ -99,21 +124,23 @@ fn get(c: &mut Criterion) {
99
124
}
100
125
101
126
criterion_group ! (
102
- benches,
103
- len,
104
- bits,
105
- new,
106
- decode,
107
- decode_encode,
108
- from_ranges,
109
- is_empty,
110
- intersection,
111
- union ,
112
- difference,
113
- symmetric_difference,
114
- cut,
115
- contains_all,
116
- contains_any,
117
- get,
127
+ name = benches;
128
+ config = profiled( ) ;
129
+ targets =
130
+ len,
131
+ bits,
132
+ new,
133
+ decode,
134
+ decode_encode,
135
+ from_ranges,
136
+ is_empty,
137
+ intersection,
138
+ union ,
139
+ difference,
140
+ symmetric_difference,
141
+ cut,
142
+ contains_all,
143
+ contains_any,
144
+ get,
118
145
) ;
119
146
criterion_main ! ( benches) ;
You can’t perform that action at this time.
0 commit comments