Skip to content

Commit

Permalink
add contains benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
llogiq committed Aug 13, 2019
1 parent e1d7e4a commit 070c83d
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/librustc_data_structures/tiny_list/tests.rs
@@ -1,7 +1,7 @@
use super::*;

extern crate test;
use test::Bencher;
use test::{Bencher, black_box};

#[test]
fn test_contains_and_insert() {
Expand Down Expand Up @@ -98,36 +98,59 @@ fn test_remove_single() {
#[bench]
fn bench_insert_empty(b: &mut Bencher) {
b.iter(|| {
let mut list = TinyList::new();
let mut list = black_box(TinyList::new());
list.insert(1);
list
})
}

#[bench]
fn bench_insert_one(b: &mut Bencher) {
b.iter(|| {
let mut list = TinyList::new_single(0);
let mut list = black_box(TinyList::new_single(0));
list.insert(1);
list
})
}

#[bench]
fn bench_contains_empty(b: &mut Bencher) {
b.iter(|| {
black_box(TinyList::new()).contains(&1)
});
}

#[bench]
fn bench_contains_unknown(b: &mut Bencher) {
b.iter(|| {
black_box(TinyList::new_single(0)).contains(&1)
});
}

#[bench]
fn bench_contains_one(b: &mut Bencher) {
b.iter(|| {
black_box(TinyList::new_single(1)).contains(&1)
});
}

#[bench]
fn bench_remove_empty(b: &mut Bencher) {
b.iter(|| {
TinyList::new().remove(&1)
black_box(TinyList::new()).remove(&1)
});
}

#[bench]
fn bench_remove_unknown(b: &mut Bencher) {
b.iter(|| {
TinyList::new_single(0).remove(&1)
black_box(TinyList::new_single(0)).remove(&1)
});
}

#[bench]
fn bench_remove_one(b: &mut Bencher) {
b.iter(|| {
TinyList::new_single(1).remove(&1)
black_box(TinyList::new_single(1)).remove(&1)
});
}

0 comments on commit 070c83d

Please sign in to comment.