Skip to content

Commit 070c83d

Browse files
committed
add contains benchmarks
1 parent e1d7e4a commit 070c83d

File tree

1 file changed

+29
-6
lines changed
  • src/librustc_data_structures/tiny_list

1 file changed

+29
-6
lines changed

src/librustc_data_structures/tiny_list/tests.rs

+29-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22

33
extern crate test;
4-
use test::Bencher;
4+
use test::{Bencher, black_box};
55

66
#[test]
77
fn test_contains_and_insert() {
@@ -98,36 +98,59 @@ fn test_remove_single() {
9898
#[bench]
9999
fn bench_insert_empty(b: &mut Bencher) {
100100
b.iter(|| {
101-
let mut list = TinyList::new();
101+
let mut list = black_box(TinyList::new());
102102
list.insert(1);
103+
list
103104
})
104105
}
105106

106107
#[bench]
107108
fn bench_insert_one(b: &mut Bencher) {
108109
b.iter(|| {
109-
let mut list = TinyList::new_single(0);
110+
let mut list = black_box(TinyList::new_single(0));
110111
list.insert(1);
112+
list
111113
})
112114
}
113115

116+
#[bench]
117+
fn bench_contains_empty(b: &mut Bencher) {
118+
b.iter(|| {
119+
black_box(TinyList::new()).contains(&1)
120+
});
121+
}
122+
123+
#[bench]
124+
fn bench_contains_unknown(b: &mut Bencher) {
125+
b.iter(|| {
126+
black_box(TinyList::new_single(0)).contains(&1)
127+
});
128+
}
129+
130+
#[bench]
131+
fn bench_contains_one(b: &mut Bencher) {
132+
b.iter(|| {
133+
black_box(TinyList::new_single(1)).contains(&1)
134+
});
135+
}
136+
114137
#[bench]
115138
fn bench_remove_empty(b: &mut Bencher) {
116139
b.iter(|| {
117-
TinyList::new().remove(&1)
140+
black_box(TinyList::new()).remove(&1)
118141
});
119142
}
120143

121144
#[bench]
122145
fn bench_remove_unknown(b: &mut Bencher) {
123146
b.iter(|| {
124-
TinyList::new_single(0).remove(&1)
147+
black_box(TinyList::new_single(0)).remove(&1)
125148
});
126149
}
127150

128151
#[bench]
129152
fn bench_remove_one(b: &mut Bencher) {
130153
b.iter(|| {
131-
TinyList::new_single(1).remove(&1)
154+
black_box(TinyList::new_single(1)).remove(&1)
132155
});
133156
}

0 commit comments

Comments
 (0)