1 #![feature(test)]
2 #![allow(clippy::unit_arg)]
3 extern crate test;
4
5 use grcov::{CovResult, Function, FunctionMap};
6 use rustc_hash::FxHashMap;
7 use test::{black_box, Bencher};
8
9 #[bench]
bench_filter_covered(b: &mut Bencher)10 fn bench_filter_covered(b: &mut Bencher) {
11 let mut functions: FunctionMap = FxHashMap::default();
12 functions.insert(
13 "f1".to_string(),
14 Function {
15 start: 1,
16 executed: true,
17 },
18 );
19 functions.insert(
20 "f2".to_string(),
21 Function {
22 start: 2,
23 executed: false,
24 },
25 );
26 let result = CovResult {
27 lines: [(1, 21), (2, 7), (7, 0)].iter().cloned().collect(),
28 branches: [].iter().cloned().collect(),
29 functions,
30 };
31 b.iter(|| black_box(grcov::is_covered(&result)));
32 }
33
34 #[bench]
bench_filter_covered_no_functions(b: &mut Bencher)35 fn bench_filter_covered_no_functions(b: &mut Bencher) {
36 let result = CovResult {
37 lines: [(1, 21), (2, 7), (7, 0)].iter().cloned().collect(),
38 branches: [].iter().cloned().collect(),
39 functions: FxHashMap::default(),
40 };
41 b.iter(|| black_box(grcov::is_covered(&result)));
42 }
43
44 #[bench]
bench_filter_uncovered_no_lines_executed(b: &mut Bencher)45 fn bench_filter_uncovered_no_lines_executed(b: &mut Bencher) {
46 let mut functions: FunctionMap = FxHashMap::default();
47 functions.insert(
48 "f1".to_string(),
49 Function {
50 start: 1,
51 executed: true,
52 },
53 );
54 functions.insert(
55 "f2".to_string(),
56 Function {
57 start: 2,
58 executed: false,
59 },
60 );
61 let result = CovResult {
62 lines: [(1, 0), (2, 0), (7, 0)].iter().cloned().collect(),
63 branches: [].iter().cloned().collect(),
64 functions: FxHashMap::default(),
65 };
66 b.iter(|| black_box(grcov::is_covered(&result)));
67 }
68
69 #[bench]
bench_filter_covered_functions_executed(b: &mut Bencher)70 fn bench_filter_covered_functions_executed(b: &mut Bencher) {
71 let mut functions: FunctionMap = FxHashMap::default();
72 functions.insert(
73 "top-level".to_string(),
74 Function {
75 start: 1,
76 executed: true,
77 },
78 );
79 functions.insert(
80 "f".to_string(),
81 Function {
82 start: 2,
83 executed: true,
84 },
85 );
86 let result = CovResult {
87 lines: [(1, 21), (2, 7), (7, 0)].iter().cloned().collect(),
88 branches: [].iter().cloned().collect(),
89 functions,
90 };
91 b.iter(|| black_box(grcov::is_covered(&result)));
92 }
93
94 #[bench]
bench_filter_covered_toplevel_executed(b: &mut Bencher)95 fn bench_filter_covered_toplevel_executed(b: &mut Bencher) {
96 let mut functions: FunctionMap = FxHashMap::default();
97 functions.insert(
98 "top-level".to_string(),
99 Function {
100 start: 1,
101 executed: true,
102 },
103 );
104 let result = CovResult {
105 lines: [(1, 21), (2, 7), (7, 0)].iter().cloned().collect(),
106 branches: [].iter().cloned().collect(),
107 functions,
108 };
109 b.iter(|| black_box(grcov::is_covered(&result)));
110 }
111
112 #[bench]
bench_filter_uncovered_functions_not_executed(b: &mut Bencher)113 fn bench_filter_uncovered_functions_not_executed(b: &mut Bencher) {
114 let mut functions: FunctionMap = FxHashMap::default();
115 functions.insert(
116 "top-level".to_string(),
117 Function {
118 start: 1,
119 executed: true,
120 },
121 );
122 functions.insert(
123 "f".to_string(),
124 Function {
125 start: 7,
126 executed: false,
127 },
128 );
129 let result = CovResult {
130 lines: [(1, 21), (2, 7), (7, 0)].iter().cloned().collect(),
131 branches: [].iter().cloned().collect(),
132 functions,
133 };
134 b.iter(|| black_box(grcov::is_covered(&result)));
135 }
136