测试环境:
CPU:Core i7-3770 3.4GHz
内存:4G
系统:64位 Windows 8.1
IDE:Visual Studio 2013
测试对象:
set,hash_set,unordered_set
map,hash_map,unordered_map
测试代码:
// STL容器性能测试 by Daven172
#include <iostream>
#include <ctime>
#include <windows.h>
#include <set>
#include <map>
#include <hash_set>
#include <hash_map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
const int NUM = 5000000;
void TestSet()
{
LARGE_INTEGER f;
QueryPerformanceFrequency(&f);
int *data = new int[NUM];
for (int i = 0; i < NUM; i++)
data[i] = rand() % NUM;
set<int> int_set;
hash_set<int> int_hash_set;
unordered_set<int> int_unordered_set;
LARGE_INTEGER c[10];
//插入
QueryPerformanceCounter(&c[0]);
for (int i &#