#include <iostream>
#include <hash_map>
#include <ctime>
using namespace std;
int main()
{
hash_map<int,int> hm;
clock_t startx = clock();
for(int i = 0; i < 10000000; i++)
hm.insert(make_pair(i,i));
cout<<"插入"<<(double)(clock()-startx)/CLOCKS_PER_SEC<<endl;
clock_t start = clock();
clock_t finish;
double totaltime;
for(int i = 0; i < 10000000; i++)
{
if(hm.find(i)== hm.end())
cout<<"Error!";
if(i%1000000 == 0)
{
finish = clock();
totaltime = (double)(finish-start)/CLOCKS_PER_SEC;
cout<<i<<" "<< totaltime << endl;
}
}
finish = clock();
totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
cout<<"\nRuntime is: "<< totaltime << "s" << endl;
//system("pause");
return 0;
}Release版本,debug太慢了
插入3.715
0 0
1000000 0.133
2000000 0.266
3000000 0.399
4000000 0.534
5000000 0.683
6000000 0.833
7000000 0.999
8000000 1.149
9000000 1.295
Runtime is: 1.441s