stl哈希表效率比对
测试代码:
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include<backward/hash_map>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
namespace just{
void monika(){
mt19937_64 mt(0x0d000721);
(测试目标)<int,int> hm;
hm.clear();
for(int i=0;i<=100000000;i++)hm[mt()]=mt();
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
just::monika();
return 0;
}
使用了unordered_map和<backward/hash_map>的hash_map
用时:
- 不使用O2时:
unordered_map66.75shash_map63.28s
- 使用O2时:
unordered_map45.63shash_map42.03s
综上所述,hash_map较unordered_map更快

浙公网安备 33010602011771号