3 ms·
std::map is incredibly slow (and allocates willy-nilly), see https://martin.ankerl.com/2019/04/01/hashmap-benchmarks-01-overview/ https://martin.ankerl.com/2019
by jcelerier 7y ago
std::map is incredibly slow (and allocates willy-nilly), see https://martin.ankerl.com/2019/04/01/hashmap-benchmarks-01-overview/ https://martin.ankerl.com/2019/04/01/hashmap-benchmarks-01-o... for a comparison of modern hash maps. Or at least boost::flat_map if you need ordering but don't do many insertions / removals and care instead for fast iteration on the map.
Note: when I say "incredibly slow", it is relative to what is possible to achieve in C++ - it will still roll over many other languages's map implementations.
- Const-me 7y agoIn some cases, the performance of std::unordered_map is fixable with a custom allocator: https://github.com/Const-me/CollectionMicrobench https://github.com/Const-me/CollectionMicrobench
- fpoling 7y agoChromium advised for their typical use cases to use std::map in favor of std::unordered_map. And they also provide own version of flat_map. [1] - https://chromium.googlesource.com/chromium/src/+/master/base/containers/README.md https://chromium.googlesource.com/chromium/src/+/master/base...