Closed NotOneRing closed 2 years ago
reserve()
does exactly what it is supposed to do: it preallocates memory so that when you insert the elements the map doesn't have to reallocate anything. The thing is, even without reserve() the implementation doesn't allocate very much. In my benchmarks, insertion speed with reserve() is faster, but the speedup is not as much.
Dear author,
Thanks so much for your reply!
You have made enormous contributions to the best Robinhood hashing implementation. Could you please give me some hints about which one should be the best hashmap to choose? My task is to insert and access elements in unordered_map<int, float>. This task requires high efficiency as the first priority and we have relatively limited memory usage. Should I choose "robin_hood::unordered map" or "ankerl::unordered_dense::map<int, float>"?
Thanks so much for your help!!!
Best regards, Bob.
That's impossible for me to say, you have to do your own benchmarks. Also, maybe this helps: https://martin.ankerl.com/2022/08/27/hashmap-bench-01/
Dear Martinus,
Thanks so much for your contributions and help!!! It really helps!!!
Best regards, Bob
Dear author,
Thanks so much for your library! It really helps!
Sorry for the inconvenience I might cause. I'm wondering if the calling of the "reserve()" function to reserve the space for the hashing_map to reduce collision(the hypothesis is: given the approximate length, the hashing allocation may be optimized) and thus could reduce the time cost. But in the experiment of "ankerl::unordered_dense::map<int, float>", it didn't show any sign of acceleration. The two versions with "reserve()" and without "reserve" get nearly the same speed. Could you please help explain the rationale behind it?
Best regards, Bob