I published a quick hashmap benchmark here:
https://github.com/matklad/hashbench
fn main() {
let n = 50_000_000;
let hm1 = {
let _t = timeit("build std::collections::HashSet");
numbers(n).collect::<std::collections::HashSet<_>>()
};
let hm2 = {
let _t = timeit("build rustc_hash::FxHashSet");
numbers(n).collect::<rustc_hash::FxHashSet<_>>()
};
let hm3 = {
let _t = timeit("build ahash::HashSet");
numbers(n).collect::<ahash::AHashSet<_>>()
};
assert!(hm1.len() == hm2.len());
assert!(hm2.len() == hm3.len());
eprintln!();
{
let _t = timeit("lookup std::collections::HasSet");
assert!(numbers(n).all(|it| hm1.contains(&it)))
}
{
let _t = timeit("lookup rustc_hash::FxHashSet");
assert!(numbers(n).all(|it| hm2.contains(&it)))
}
{
let _t = timeit("lookup ahash::AHashSet");
assert!(numbers(n).all(|it| hm3.contains(&it)))
}
}
Here's what the output looks like (checked on two cpu)
build std::collections::HashSet 4.35s *
build rustc_hash::FxHashSet 3.76s
build ahash::HashSet 3.92s
lookup std::collections::HasSet 5.33s *
lookup rustc_hash::FxHashSet 1.89s
lookup ahash::AHashSet 2.78s
Can anyone explain the *
entries? How come lookup is costlier than construction?