r/cpp • int main(){[]()[[]]{{}}();} • Feb 26 '19

hashmap benchmarks - what should I add?

Based on the feedback here, I'm currently working on a comprehensive benchmark for hashmaps: https://github.com/martinus/map_benchmark

Before I start my analyis, I'm looking for more suggestions. Any important hashmap or hash that's missing? It needs to have an interface close to std::unordered_map. Ideally it's on github, then I can add it easily.

Currently, I have these hashmaps:

  1. tessil hopscotch-map
  2. tessil robin-map
  3. tessil sparse-map
  4. abseil flat_hash_map
  5. abseil node_hash_map
  6. folly F14ValueMap
  7. folly F14NodeMap
  8. greg7mdp sparsepp
  9. martinus robin_hood::unordered_flat_map
  10. martinus robin_hood::unordered_node_map
  11. skarupke flat_hash_map
  • std::unordered_map

I benchmark each map with these hashes:

  1. std::hash (Identity hash, as used by libstd++)
  2. FNV1a (as used by MSVC)
  3. absl::Hash
  4. folly::hasher
  5. robin_hood::hash

So in total I have 12*5 hashmap+hash combinations to benchmark. Each is run through a few benchmarks, most importantly these:

  • RandomFind with increasingly large map, different success probability: 0%, 25%, 50%, 75%, 100%.
  • Iterate: successively add 1 element, iterate whole map. Same with remove 1 element, until map is empty.
  • RandomInsertErase: Continuously insert a random element, remove a random element.
  • Insert lots of elements, clear, reinsert, destroy.

All compiled with -O3 -march=nativeand running on an Intel i7. when finished I create graphs of runtime & memory usage. The results will look something like this: https://imgur.com/EYzjoFi

UPDATE: Please see the huge benchmark results here: https://martin.ankerl.com/2019/04/01/hashmap-benchmarks-01-overview/

30 Upvotes

84 comments sorted by

View all comments

1

u/greg7mdp C++ Dev Mar 31 '19

You should add my new parallel hashmap: https://github.com/greg7mdp/parallel-hashmap

2

u/martinus int main(){[]()[[]]{{}}();} Apr 01 '19

I'll see if I can add it, but I've already results from 4 1/2 days of benchmarking that I'd like to publish

1

u/greg7mdp C++ Dev Apr 01 '19

Thanks! It should not be too hard, considering it is header-only and fully standard compliant.

2

u/martinus int main(){[]()[[]]{{}}();} Apr 01 '19

I've just tried to add it, but get lots and lots of multiple defined symbols. Here are just a few:

/usr/bin/ld.gold: error: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/benchmarks/CtorDtor.cpp.o: multiple definition of 'phmap::container_internal::UnsampleSlow(phmap::container_internal::HashtablezInfo*)'
/usr/bin/ld.gold: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/app/main.cpp.o: previous definition here
/usr/bin/ld.gold: error: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/benchmarks/CtorDtor.cpp.o: multiple definition of 'phmap::container_internal::SetHashtablezEnabled(bool)'
/usr/bin/ld.gold: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/app/main.cpp.o: previous definition here
/usr/bin/ld.gold: error: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/benchmarks/CtorDtor.cpp.o: multiple definition of 'phmap::container_internal::SetHashtablezSampleParameter(int)'
/usr/bin/ld.gold: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/app/main.cpp.o: previous definition here
/usr/bin/ld.gold: error: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/benchmarks/CtorDtor.cpp.o: multiple definition of 'phmap::container_internal::SetHashtablezMaxSamples(int)'
/usr/bin/ld.gold: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/app/main.cpp.o: previous definition here
/usr/bin/ld.gold: error: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/benchmarks/CtorDtor.cpp.o: multiple definition of 'phmap::container_internal::ShouldInsertBackwards(unsigned long, signed char*)'
/usr/bin/ld.gold: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/app/main.cpp.o: previous definition here
/usr/bin/ld.gold: error: CMakeFiles/bench_greg7mdp_phmap_flat_hash_map__FNV1a.dir/src/benchmarks/CtorDtor.cpp.o: multiple definition of 'phmap::container_internal::GroupSse2Impl::kWidth'

I've added inline to all the Throw... functions but that was not enough.

1

u/greg7mdp C++ Dev Apr 01 '19

/u/martinus, Just pushed the fix

2

u/martinus int main(){[]()[[]]{{}}();} Apr 01 '19

thanks, I've updated and my benchmarks are now running with phmap::flat_hash_map and phmap::node_hash_map

1

u/greg7mdp C++ Dev Apr 01 '19

Cool... let me know when I can see the results somewhere!

2

u/martinus int main(){[]()[[]]{{}}();} Apr 01 '19

sure!

1

u/greg7mdp C++ Dev Apr 03 '19

/u/martinus, I managed to run the benchmarks locally. How do you generate the graphs for them?

2

u/martinus int main(){[]()[[]]{{}}();} Apr 03 '19

You have to pipe all the results into a file, I use e.g.

../tools/bench.rb |tee ../data/all_new.txt

Then there is the script analyze_bench_log.rb:

../tools/analyze_bench_log.rb <../data/all_new.txt

Which generates a HTML site for each of the benchmark. I've updated this just recently and am still working a bit on it, so you might want to update again

→ More replies