下面是在一台 aws r4.xlarge
机械上的测试效果(注重编译的时刻肯定要加 -O2):
std::map<int, int> => 51866903 std::unordered_map<int, int> => 3838175 std::unordered_map<int, int, nohashint> => 3508570 std::unordered_map<int, int>(N) => 3804471 boost::unordered_map<int, int> => 3291384 boost::unordered_map<int, int, nohashint> => 3293934 boost::unordered_map<int, int>(N) => 3265856 google::dense_hash_map<int, int> => 785969 google::dense_hash_map<int, int, nohashint> => 784455 google::dense_hash_map<int, int>(N) => 899262 tsl::hopscotch_map<int, int> => 654668 tsl::hopscotch_map<int, int, nohashint> => 680964 tsl::hopscotch_map<int, int>(N) => 663607 tsl::robin_map<int, int> => 406176 tsl::robin_map<int, int, nohashint> => 411358 tsl::robin_map<int, int>(N) => 409993
能够看到 tsl::robin_map 的机能基本上能到达 std::unordered_map 的 10 倍,这个机能和操作系统以及库版本也有肯定关联,现实生产环境中发起把代码拉下来在本身的环境下测试一下
我们线上用 tsl::robin_map 替换了本来的 boost::unordered_map,团体机能提升了 5 倍,这内里固然也还包含了一些其他的优化,这个优化算是比较大的优化点了
相干文章:
MySQL慢查询查找和调优测试
php函数的查找机能测试
相干视频:
C++ 手册教程
以上就是案例分享c++ map的运用和 查找机能测试的细致内容,更多请关注ki4网别的相干文章!