我认为这个问题得到了部分回答,因为没有提供有关“int”类型作为键的性能的信息。我进行了自己的分析,发现在使用整数作为键的许多实际情况下,std::map 的性能(在速度上)优于 std::unordered_map。
整数测试
测试场景包括使用顺序和随机键填充映射,并使用长度在 [17:119] 范围内的字符串值(以 17 的倍数)。使用元素计数在 [10:100000000] 范围内以 10 的幂执行的测试.
Labels:
Map64: std::map<uint64_t,std::string>
Map32: std::map<uint32_t,std::string>
uMap64: std::unordered_map<uint64_t,std::string>
uMap32: std::unordered_map<uint32_t,std::string>
插入
Labels:
Sequencial Key Insert: maps were constructed with keys in the range [0-ElementCount]
Random Key Insert: maps were constructed with random keys in the full range of the type

插入结论:
- 当映射大小低于 10000 个元素时,在 std::map 中插入扩展键往往优于 std::unordered_map。
- 在 std::map 中插入密集键不会与 1000 个元素下的 std::unordered_map 存在性能差异。
- 在所有其他情况下,std::unordered_map 往往执行得更快。
抬头
Labels:
Sequential Key - Seq. Search: Search is performed in the dense map (keys are sequential). All searched keys exists in the map.
Random Key - Rand. Search: Search is performed in the sparse map (keys are random). All searched keys exists in the map.
(label names can be miss leading, sorry about that)

查找结论:
- 当地图大小低于 1000000 个元素时,搜索传播 std::map 的性能往往略优于 std::unordered_map。
- 在密集的 std::map 上搜索优于 std::unordered_map
查找失败
Labels:
Sequential Key - Rand. Search: Search is performed in the dense map. Most keys do not exists in the map.
Random Key - Seq. Search: Search is performed in the sparse map. Most keys do not exists in the map.
(label names can be miss leading, sorry about that)

查找失败的结论:
一般结论
即使在需要速度的情况下,整数键的 std::map 在许多情况下仍然是更好的选择。作为一个实际的例子,我有一个查找永远不会失败的字典,虽然键的分布很稀疏,但它的执行速度与 std::unordered_map 相同,因为我的元素计数低于 1K。并且内存占用显着降低。
字符串测试
作为参考,我在这里介绍了string[string]映射的时间安排。密钥字符串由随机 uint64_t 值形成,值字符串与其他测试中使用的相同。
Labels:
MapString: std::map<std::string,std::string>
uMapString: std::unordered_map<std::string,std::string>

评估平台
操作系统:Linux - OpenSuse Tumbleweed
编译器:g++ (SUSE Linux) 11.2.1 20210816
CPU:Intel(R) Core(TM) i9-9900 CPU @ 3.10GHz
内存:64Gb