Skip to content

HashMap slow compared to hashbrown implementation #64214

Closed
@stefanhoelzl

Description

@stefanhoelzl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions