__gnu_cxx::hash showing major performance difference when the key is a pointer? while unordered_map is fast

Viewed 22

I observed for a million insertion, hash_map (using __gnu_cxx::hash) took around 224 sec while unordered_map<> took only 2 sec for the same.

#include <ext/hash_map>

typedef hash_map<char*, std::string > hashMap;
typedef unordered_map<char*, std::string> stdMap;

hashMap hM;
int N = 1000000;
    for (int i = 0; i < N; i++) {
        std::string ss = std::to_string(i+1);
        char *id = new char;
        hM->insert(make_pair(id,ss));
    }

Also if I change char* to char or int, then hash_map also take less than 2 sec.

0 Answers
Related