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实现性能比较的更多相关文章

  1. list 、set 、map 粗浅性能对比分析

    list .set .map 粗浅性能对比分析   不知道有多少同学和我一样,工作五年了还没有仔细看过list.set的源码,一直停留在老师教导的:"LinkedList插入性能比Array ...

  2. 目标检测模型的性能评估--MAP(Mean Average Precision)

    目标检测模型中性能评估的几个重要参数有精确度,精确度和召回率.本文中我们将讨论一个常用的度量指标:均值平均精度,即MAP. 在二元分类中,精确度和召回率是一个简单直观的统计量,但是在目标检测中有所不同 ...

  3. MySQL Innodb数据库性能实践——热点数据性能

    摘要: 对于大部分的应用来说,都存在热点数据的访问,即:某些数据在一定时间内的访问频率要远远高于其它数据. 常见的热点数据有“最新的新闻”.“最热门的新闻”.“下载量最大”的电影等. 为了了解MySQ ...

  4. Android App性能优化笔记之一:性能优化是什么及为什么?

    By Long Luo   周星驰的电影<功夫>里面借火云邪神之口说出了一句至理名言:“天下武功,唯快不破”. 在移动互联网时代,同样如此,留给一个公司的窗口往往只有很短的时间,如何把握住 ...

  5. 微擎开启性能优化里面的性能优化memcache内存优化及数据库读写分离

    http://www.mitusky.com/forum.php?mod=viewthread&tid=3135 [微擎 安装使用] 微擎开启性能优化里面的性能优化memcache内存优化及数 ...

  6. PHP性能:序——谈性能

    PHP性能:序——谈性能 这里不谈PHP的性能和其他语言的性能,这里讨论PHP自身的性能问题. 性能是什么? 通俗的来讲,性能,就是在固定的环境下能做的事情的多少. 为什么要性能? 1.每一个软件或网 ...

  7. 性能优化——Web前端性能优化

    核心知识点: 1.排查网站性能瓶颈的手法:分析各个环节的日志,找出异常部分 2.Web前端:网站业务逻辑之前的部分(浏览器.图片服务.CDN) 3.优化手段 1)浏览器优化 (1)减少http请求 a ...

  8. Java生鲜电商平台-API请求性能调优与性能监控

    Java生鲜电商平台-API请求性能调优与性能监控 背景 在做性能分析时,API的执行时间是一个显著的指标,这里使用SpringBoot AOP的方式,通过对接口添加简单注解的方式来打印API的执行时 ...

  9. web性能优化-网络传输性能优化

    浏览器工作原理:https://www.cnblogs.com/thonrt/p/10008220.html 浏览器渲染原理: https://www.cnblogs.com/thonrt/p/100 ...

随机推荐

  1. hdu4027Can you answer these queries?【线段树】

    A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...

  2. pandas将DataFrame的列变成行索引

    pandas提供了set_index方法可以将DataFrame的列(多列)变成行索引,通过reset_index方法可以将层次化索引的级别会被转移到列里面. 1.DataFrame的set_inde ...

  3. 数据结构——栈(C语言实现)

    #include <stdio.h> #include <stdlib.h> #include<string.h> #include<malloc.h> ...

  4. pyobjc-framework-Cocoa 5.1.2

    Introduction — PyObjC - the Python to Objective-C bridge https://pyobjc.readthedocs.io/en/latest/ py ...

  5. os.stat(filename).st_size 文件信息

    os.path.getsize(i) py36\Lib\genericpath.py def getsize(filename): """Return the size ...

  6. 眠眠interview Question

    1.  Wkwebkit在异步回调  如何像webview的回调 一样在主线程回调.可以使用runloop 解决么? dispatch get main queue http://www.jiansh ...

  7. ArcGIS Server 服务器日志(待修改)

    有时遇到服务相关错误,需要查看日志来排查,这里简单写下日志相关操作. 服务器日志:http://resources.arcgis.com/zh-cn/help/main/10.2/index.html ...

  8. CF576C Points on Plane 构造

    正解:构造 解题报告: 先放下传送门趴QAQ 话说我jio得这题好玄学啊,,,就是,我实在觉得我这题做得完美无缺了?可就是过不去,,,而且它告诉我的奇异错误是"wrong output fo ...

  9. (四)Web应用开发---系统架构图

    系统宏观架构:EASYUI+MVC 系统架构图一. 系统架构图二.

  10. Celery框架简单实例

    Python 中可以使用Celery框架 Celery框架是提供异步任务处理的框架,有两种用法,一种:应用程式发布任务消息,后台Worker监听执行,好处在于不影响应用程序继续执行.第二种,设置定时执 ...