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_map 66.75s
    • hash_map 63.28s
  • 使用O2时:
    • unordered_map 45.63s
    • hash_map 42.03s

综上所述,hash_mapunordered_map更快

posted @ 2025-08-08 11:29  NotMonika  阅读(16)  评论(0)    收藏  举报