Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HashMap slow compared to hashbrown implementation #64214

Closed
stefanhoelzl opened this issue Sep 6, 2019 · 1 comment
Closed

HashMap slow compared to hashbrown implementation #64214

stefanhoelzl opened this issue Sep 6, 2019 · 1 comment

Comments

@stefanhoelzl
Copy link

stefanhoelzl commented Sep 6, 2019

Since Rust 1.36 the HashMap implementation in the standard library should be ported from hashbrown (see #56241)).

But when benchmarking both, hashbrown is a lot faster (3x) on inserts than the HashMap in the standard library:

$ cargo bench
running 2 tests
test tests::brown ... bench:           4 ns/iter (+/- 3)
test tests::std   ... bench:          14 ns/iter (+/- 4)

Here is my benchmarking code

#![feature(test)]
extern crate test;
extern crate hashbrown;

#[cfg(test)]
mod tests {
    use test::Bencher;
    use hashbrown::HashMap as BrownMap;
    use std::collections::HashMap as StdMap;

    #[bench]
    fn brown(b: &mut Bencher) {
        let mut map = BrownMap::new();
        b.iter(|| map.insert(0, 0));
    }

    #[bench]
    fn std(b: &mut Bencher) {
        let mut map = StdMap::new();
        b.iter(|| map.insert(0, 0));
    }
}

Meta

$ rustc --version --verbose
rustc 1.39.0-nightly (b9de4ef89 2019-09-03)
binary: rustc
commit-hash: b9de4ef89e0e53099a084001b26ec3207c5f8391
commit-date: 2019-09-03
host: x86_64-pc-windows-msvc
release: 1.39.0-nightly
LLVM version: 9.0

on Windows 10

@Mark-Simulacrum
Copy link
Member

This is expected, as std has a different (slower) hasher due to wanting default DDOS protection and such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants