The standard library’s maps are, indeed, inherently slow (std::map
especially but std::unoredered_map
as well). Google’s Chandler Carruth explains this in his CppCon 2014 talk; in a nutshell: std::unordered_map
is cache-unfriendly because it uses linked lists as buckets.
This SO question mentioned some efficient hash map implementations – use one of those instead.