c++性能之map实现性能比较
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还没有研究,不确定具体什么原因导致。
c++性能之map实现性能比较的更多相关文章
- list 、set 、map 粗浅性能对比分析
list .set .map 粗浅性能对比分析 不知道有多少同学和我一样,工作五年了还没有仔细看过list.set的源码,一直停留在老师教导的:"LinkedList插入性能比Array ...
- 目标检测模型的性能评估--MAP(Mean Average Precision)
目标检测模型中性能评估的几个重要参数有精确度,精确度和召回率.本文中我们将讨论一个常用的度量指标:均值平均精度,即MAP. 在二元分类中,精确度和召回率是一个简单直观的统计量,但是在目标检测中有所不同 ...
- MySQL Innodb数据库性能实践——热点数据性能
摘要: 对于大部分的应用来说,都存在热点数据的访问,即:某些数据在一定时间内的访问频率要远远高于其它数据. 常见的热点数据有“最新的新闻”.“最热门的新闻”.“下载量最大”的电影等. 为了了解MySQ ...
- Android App性能优化笔记之一:性能优化是什么及为什么?
By Long Luo 周星驰的电影<功夫>里面借火云邪神之口说出了一句至理名言:“天下武功,唯快不破”. 在移动互联网时代,同样如此,留给一个公司的窗口往往只有很短的时间,如何把握住 ...
- 微擎开启性能优化里面的性能优化memcache内存优化及数据库读写分离
http://www.mitusky.com/forum.php?mod=viewthread&tid=3135 [微擎 安装使用] 微擎开启性能优化里面的性能优化memcache内存优化及数 ...
- PHP性能:序——谈性能
PHP性能:序——谈性能 这里不谈PHP的性能和其他语言的性能,这里讨论PHP自身的性能问题. 性能是什么? 通俗的来讲,性能,就是在固定的环境下能做的事情的多少. 为什么要性能? 1.每一个软件或网 ...
- 性能优化——Web前端性能优化
核心知识点: 1.排查网站性能瓶颈的手法:分析各个环节的日志,找出异常部分 2.Web前端:网站业务逻辑之前的部分(浏览器.图片服务.CDN) 3.优化手段 1)浏览器优化 (1)减少http请求 a ...
- Java生鲜电商平台-API请求性能调优与性能监控
Java生鲜电商平台-API请求性能调优与性能监控 背景 在做性能分析时,API的执行时间是一个显著的指标,这里使用SpringBoot AOP的方式,通过对接口添加简单注解的方式来打印API的执行时 ...
- web性能优化-网络传输性能优化
浏览器工作原理:https://www.cnblogs.com/thonrt/p/10008220.html 浏览器渲染原理: https://www.cnblogs.com/thonrt/p/100 ...
随机推荐
- hdu1540 Tunnel Warfare【线段树】
During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...
- windows下安装pytorch
安装: https://blog.csdn.net/xiangxianghehe/article/details/80103095 Windows下通过pip安装PyTorch 0.4.0 impor ...
- 2018java面试知识汇总
1. 多线程 1.1 多线程7种同步方法? 答:同步方法 同步代码块 使用重入锁实现线程同步(ReentrantLock) 使用特殊域变量(volatile)实现同步(每次重新计算,安全但并非一致) ...
- -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
本人使用mac系统,命令行工具使用的iterm2,登录自己的云主机的时候 每次都要提示如下错误 -bash: warning: setlocale: LC_CTYPE: cannot change l ...
- vue - vue + vue-router + vuex 简单项目
简单的,我的首页,我的笔记项目 vue + vue-router + vuex View + VM(ViewModel) + Model (webpack) vue init webpack lint ...
- html+css小总结
html+css小总结 1.块级元素 <div> <h1> <hr /> <p> <pre> <ol> <ul> & ...
- IO流(2)创建文件或文件夹
创建功能: *public boolean createNewFile():创建文件 如果存在这样的文件,就不创建了 *public boolean mkdir():创建文件夹 如果存在这样的文件夹, ...
- windows平台mysql密码设置
登录mysql默认没有指定账号 查看默认账号是谁 select user(); mysql> select user();+----------------+| user() |+------- ...
- logstash采集tomcat日志、mysql错误日志
input{ file { path => "/opt/Tomcat7.0.28/logs/*.txt" start_position => "beginni ...
- openstack 部署笔记--dashboard
控制节点 # yum install openstack-dashboard # vim /etc/openstack-dashboard/local_settings OPENSTACK_HOST ...