Home >Backend Development >C#.Net Tutorial >Case sharing on the use of c++ map and finding performance tests
Recently I am doing performance tuning for the recommendation service. The main logic of this service is to use offline calculated model data to score each advertisement in the request, and then return the sorting results of these advertisements. The scoring process here actually uses The data in the request is combined into various keys to check a large map. This kind of calculation is very much and has become a major performance bottleneck. The code is relatively old and uses boost::unordered_map. In order to solve this problem, I found some Comparing the third-party library and the standard library
The following are the test results on an aws r4.xlarge
machine (note that -O2 must be added when compiling):
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
You can see that the performance of tsl::robin_map can basically reach 10 times that of std::unordered_map. This performance is also related to the operating system and library version. In the actual production environment, it is recommended to pull down the code and run it in your own environment. Let’s test it next
We replaced the original boost::unordered_map with tsl::robin_map online, and the overall performance increased by 5 times. Of course, it also includes some other optimizations. This optimization is relatively large. The optimization point
Related articles:
MySQL slow query search and tuning test
php function search performance test
Related videos:
The above is the detailed content of Case sharing on the use of c++ map and finding performance tests. For more information, please follow other related articles on the PHP Chinese website!