小编hyt*_*day的帖子

为什么我机器上的hash_map和unordered_map非常慢?

我用这段代码测试了它们(在Visual Studio 2010 sp1上):

#include <ctime>
#include <iostream>
#include <map>
#include <unordered_map>
#include <hash_map>

int main()
{ 
    clock_t time;
    int LOOP = (1 << 16);
    std::map<int, int> my_map;
    std::unordered_map<int, int> map_unordered_map;
    std::hash_map<int, int> my_hash_map;

    time = clock();
    for (int i = 0; i != LOOP; ++i)
    {
        my_map[i] = i;
    }
    std::cout << "map: " << ((double)(clock() - time) / CLOCKS_PER_SEC) << std::endl;

    time = clock();
    for (int i = 0; i != LOOP; ++i)
    {
        map_unordered_map[i] = i;
    } …
Run Code Online (Sandbox Code Playgroud)

c++ unordered-map hashmap map

4
推荐指数
1
解决办法
1685
查看次数

标签 统计

c++ ×1

hashmap ×1

map ×1

unordered-map ×1