http://www.cnblogs.com/zhjh256/p/6346501.html讲述了基本的map操作,在测试的时候,发现map的性能极为低下,与java相比相差了接近200倍。测试的逻辑如下:

    // map定义
map<int, FirstCPPCls*> mapStudent;
for (i=;i<;i++) {
FirstCPPCls clz;
clz.setAppVersion("12.32.33");
clz.setClusterName("osm-service");
clz.setCompanyId("");
clz.setServiceId("sysL.1.223");
clz.setSubSystemId("");
clz.setSystemId("");
mapStudent.insert(pair<int, FirstCPPCls*>(i, &clz));
} // 获取时间相对计数器, vc专用
begin = GetTickCount();
for (j=;j<;j++) {
for (f=;f<;f++) {
// map查找
mapStudent.find(f);
}
}
end = GetTickCount(); // 打印时间差
cout << "Map查找耗时:" << (end - begin) << endl; // 平均4秒左右
system("pause");

在java中相同的实现,get 100 0000次只花费了20ms。于是搜索 c++ map性能,看了两个帖子如下:

http://blog.csdn.net/a418382926/article/details/22302907

http://blog.sina.com.cn/s/blog_5f93da790101hxxi.html

http://www.ideawu.net/blog/archives/751.html

随后,进行hash_map和unordered_map测试,如下:

    // hash_map定义
hash_map<int, FirstCPPCls*> hash_mapStudent;
for (i=;i<;i++) {
FirstCPPCls clz;
clz.setAppVersion("12.32.33");
clz.setClusterName("osm-service");
clz.setCompanyId("");
clz.setServiceId("sysL.1.223");
clz.setSubSystemId("");
clz.setSystemId("");
hash_mapStudent.insert(pair<int, FirstCPPCls*>(i, &clz));
} // 获取时间相对计数器, vc专用
begin = GetTickCount();
for (j=;j<;j++) {
for (f=;f<;f++) {
// map查找
hash_mapStudent.find(f);
}
}
end = GetTickCount(); // 打印时间差
cout << "HashMap查找耗时:" << (end - begin) << endl; // 平均4秒左右
system("pause"); // hash_map定义
unordered_map<int, FirstCPPCls*> unordered_mapStudent;
for (i=;i<;i++) {
FirstCPPCls clz;
clz.setAppVersion("12.32.33");
clz.setClusterName("osm-service");
clz.setCompanyId("");
clz.setServiceId("sysL.1.223");
clz.setSubSystemId("");
clz.setSystemId("");
unordered_mapStudent.insert(pair<int, FirstCPPCls*>(i, &clz));
} // 获取时间相对计数器, vc专用
begin = GetTickCount();
for (j=;j<;j++) {
for (f=;f<;f++) {
// map查找
unordered_mapStudent.find(f);
}
}
end = GetTickCount(); // 打印时间差
cout << "UnorderedMap查找耗时:" << (end - begin) << endl; // 平均4秒左右
system("pause");

输出如下:

HashMap查找耗时:1610
请按任意键继续. . .
UnorderedMap查找耗时:1797
请按任意键继续. . .

虽然,相比std::map,确实提升了50%多,但是跟java,还是慢的一塌糊涂,因为对stl还没有研究,不确定具体什么原因导致。

最新文章

  1. python 生成器等语法
  2. [hdu 4416]Good Article Good sentence
  3. Python字典笔记
  4. 【AngularJs】---JSONP跨域访问数据传输
  5. Ubuntu环境下手动配置tomcat
  6. java_method_readFile读取文件文本txt
  7. 将日志写入EventLog
  8. IDisposable接口详解
  9. java 解析 xml (DOM方法全)
  10. SE 2014 年4月21日(二)
  11. 浏览器缓存机制&lt;转&gt;
  12. MARKY一下。
  13. Caffe 深度学习框架上手教程
  14. 25个c#知识点
  15. 使用Fiddler重定向App的网络请求
  16. 博客和Github简单练习
  17. AngularJS - Directive Restrictions
  18. 微信小程序 微信支付
  19. python struct详解
  20. COALESCE操作符

热门文章

  1. POJ--3321 Apple Tree(树状数组+dfs(序列))
  2. 老师的blog整理
  3. 计蒜客 30999 - Sum - [找规律+线性筛][2018ICPC南京网络预赛J题]
  4. codeforces 894B - Ralph And His Magic Field - [数学题]
  5. CCCC L2-007. 家庭房产 建图 XJB模拟
  6. RHEL6 Systemtap 安装笔记
  7. java.io.File实战
  8. oracle(六) physical read and logical read
  9. qt——QT中QWidget、QDialog及QMainWindow的区别
  10. Sql Server 2016 Always On集群搭建