Add some simple benchmarks.

This commit is contained in:
Chris Morgan 2014-06-12 22:25:17 +10:00
parent 571142cfcf
commit 97522ab766
2 changed files with 31 additions and 0 deletions

View file

@ -39,6 +39,9 @@ build/quicktest: $(SRC)
# build/test --test
test: anymap doctest
bench: anymap build/test
build/test --bench
doctest: $(SRC) $(LIB)
$(RUSTDOC) -L build --test src/lib.rs

View file

@ -7,6 +7,9 @@
variant_size_difference, managed_heap_memory, unnecessary_typecast,
missing_doc, unused_result, deprecated_owned_vector)]
#[cfg(test)]
extern crate test;
use std::any::{Any, AnyRefExt, AnyMutRefExt};
use std::intrinsics::TypeId;
use std::collections::HashMap;
@ -71,3 +74,28 @@ impl AnyMap {
self.data.remove(&TypeId::of::<T>());
}
}
#[bench]
fn bench_insertion(b: &mut ::test::Bencher) {
b.iter(|| {
let mut data = AnyMap::new();
data.insert(42i);
})
}
#[bench]
fn bench_find_missing(b: &mut ::test::Bencher) {
b.iter(|| {
let data = AnyMap::new();
assert_eq!(data.find(), None::<&int>);
})
}
#[bench]
fn bench_find_present(b: &mut ::test::Bencher) {
b.iter(|| {
let mut data = AnyMap::new();
data.insert(42i);
assert_eq!(data.find(), Some(&42i));
})
}