Add some simple benchmarks.
This commit is contained in:
parent
571142cfcf
commit
97522ab766
3
Makefile
3
Makefile
|
@ -39,6 +39,9 @@ build/quicktest: $(SRC)
|
||||||
# build/test --test
|
# build/test --test
|
||||||
test: anymap doctest
|
test: anymap doctest
|
||||||
|
|
||||||
|
bench: anymap build/test
|
||||||
|
build/test --bench
|
||||||
|
|
||||||
doctest: $(SRC) $(LIB)
|
doctest: $(SRC) $(LIB)
|
||||||
$(RUSTDOC) -L build --test src/lib.rs
|
$(RUSTDOC) -L build --test src/lib.rs
|
||||||
|
|
||||||
|
|
28
src/lib.rs
28
src/lib.rs
|
@ -7,6 +7,9 @@
|
||||||
variant_size_difference, managed_heap_memory, unnecessary_typecast,
|
variant_size_difference, managed_heap_memory, unnecessary_typecast,
|
||||||
missing_doc, unused_result, deprecated_owned_vector)]
|
missing_doc, unused_result, deprecated_owned_vector)]
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
extern crate test;
|
||||||
|
|
||||||
use std::any::{Any, AnyRefExt, AnyMutRefExt};
|
use std::any::{Any, AnyRefExt, AnyMutRefExt};
|
||||||
use std::intrinsics::TypeId;
|
use std::intrinsics::TypeId;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -71,3 +74,28 @@ impl AnyMap {
|
||||||
self.data.remove(&TypeId::of::<T>());
|
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));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue