Skip to content

Commit be051ad

Browse files
committed
Create benchmarks for BTreeMap::range
1 parent fc07615 commit be051ad

File tree

1 file changed

+56
-0
lines changed
  • src/liballoc/benches/btree

1 file changed

+56
-0
lines changed

src/liballoc/benches/btree/map.rs

+56
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::BTreeMap;
22
use std::iter::Iterator;
3+
use std::ops::Bound::{Excluded, Unbounded};
34
use std::vec::Vec;
45

56
use rand::{seq::SliceRandom, thread_rng, Rng};
@@ -200,3 +201,58 @@ pub fn first_and_last_100(b: &mut Bencher) {
200201
pub fn first_and_last_10k(b: &mut Bencher) {
201202
bench_first_and_last(b, 10_000);
202203
}
204+
205+
#[bench]
206+
pub fn range_excluded_excluded(b: &mut Bencher) {
207+
let size = 144;
208+
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
209+
b.iter(|| {
210+
for first in 0..size {
211+
for last in first + 1..size {
212+
black_box(map.range((Excluded(first), Excluded(last))));
213+
}
214+
}
215+
});
216+
}
217+
218+
#[bench]
219+
pub fn range_excluded_unbounded(b: &mut Bencher) {
220+
let size = 144;
221+
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
222+
b.iter(|| {
223+
for first in 0..size {
224+
black_box(map.range((Excluded(first), Unbounded)));
225+
}
226+
});
227+
}
228+
229+
#[bench]
230+
pub fn range_included_included(b: &mut Bencher) {
231+
let size = 144;
232+
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
233+
b.iter(|| {
234+
for first in 0..size {
235+
for last in first..size {
236+
black_box(map.range(first..=last));
237+
}
238+
}
239+
});
240+
}
241+
242+
#[bench]
243+
pub fn range_included_unbounded(b: &mut Bencher) {
244+
let size = 144;
245+
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
246+
b.iter(|| {
247+
for first in 0..size {
248+
black_box(map.range(first..));
249+
}
250+
});
251+
}
252+
253+
#[bench]
254+
pub fn range_unbounded_unbounded(b: &mut Bencher) {
255+
let size = 144;
256+
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
257+
b.iter(|| map.range(..));
258+
}

0 commit comments

Comments
 (0)