Skip to content

Commit

Permalink
Create benchmarks for BTreeMap::range
Browse files Browse the repository at this point in the history
  • Loading branch information
ssomers committed Feb 6, 2020
1 parent fc07615 commit be051ad
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/liballoc/benches/btree/map.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::BTreeMap;
use std::iter::Iterator;
use std::ops::Bound::{Excluded, Unbounded};
use std::vec::Vec;

use rand::{seq::SliceRandom, thread_rng, Rng};
Expand Down Expand Up @@ -200,3 +201,58 @@ pub fn first_and_last_100(b: &mut Bencher) {
pub fn first_and_last_10k(b: &mut Bencher) {
bench_first_and_last(b, 10_000);
}

#[bench]
pub fn range_excluded_excluded(b: &mut Bencher) {
let size = 144;
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
b.iter(|| {
for first in 0..size {
for last in first + 1..size {
black_box(map.range((Excluded(first), Excluded(last))));
}
}
});
}

#[bench]
pub fn range_excluded_unbounded(b: &mut Bencher) {
let size = 144;
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
b.iter(|| {
for first in 0..size {
black_box(map.range((Excluded(first), Unbounded)));
}
});
}

#[bench]
pub fn range_included_included(b: &mut Bencher) {
let size = 144;
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
b.iter(|| {
for first in 0..size {
for last in first..size {
black_box(map.range(first..=last));
}
}
});
}

#[bench]
pub fn range_included_unbounded(b: &mut Bencher) {
let size = 144;
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
b.iter(|| {
for first in 0..size {
black_box(map.range(first..));
}
});
}

#[bench]
pub fn range_unbounded_unbounded(b: &mut Bencher) {
let size = 144;
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
b.iter(|| map.range(..));
}

0 comments on commit be051ad

Please sign in to comment.