公子周

                         --不乱于心,不困于情
随笔 - 3, 文章 - 0, 评论 - 5, 引用 - 0
数据加载中……

高效的hash_map

#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

posted on 2012-07-07 20:45 公子周 阅读(1366) 评论(1)  编辑 收藏 引用 所属分类: 字符串处理

评论

# re: 高效的hash_map  回复  更多评论   

Good....
2012-07-08 16:32 | eryar

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理