利用unordered_map代替hash_map

  • 实验环境

    1. 操作系统 fedora9
    2. 编译器版本 gcc4.3
  • 实验方式
  各种map使用插入和查找,比较速度和相关性能
  • 代码

map类型 插入速度 插入和查找速度
hashmap 0m0.123s 0m0.369s
map 0m0.190s 0m0.681s
unordered_map 0m0.123s 0m0.315s
  • 为什么要使用unordered_map代替hash_map?

    • 因为标准化的推进,unordered_map原来属于boost分支和std::tr1中,而hash_map属于非标准容器。
    • 另外,使用之后,感觉速度和hash_map差不多,但是支持string做key,也可以使用复杂的对象作为key。
    • gxx需要添加编译选项:-std=gnu++0x或者-std=c++0x
    • 在/usr/include/c++/4.3.0/backward/backward_warning.h文件中,明确写道:

This file includes at least one deprecated or antiquated header which \ may be removed without further notice at a future date. Please use a \ non-deprecated interface with equivalent functionality
instead. For a \ listing of replacement headers and interfaces, consult the file \ backward_warning.h. To disable this warning use -Wno-deprecated.

/* A list of valid replacements is as follows:

Use: Instead of: 

<sstream>, basic_stringbuf <strstream>, strstreambuf

<sstream>, basic_istringstream <strstream>, istrstream

<sstream>, basic_ostringstream <strstream>, ostrstream

<sstream>, basic_stringstream <strstream>, strstream

<unordered_set>, unordered_set <ext/hash_set>, hash_set

<unordered_set>, unordered_multiset <ext/hash_set>, hash_multiset

<unordered_map>, unordered_map <ext/hash_set>, hash_map

<unordered_map>, unordered_multimap <ext/hash_set>, hash_multimap

<functional>, bind <functional>, binder1st

<functional>, bind <functional>, binder2nd

<functional>, bind <functional>, bind1st

<functional>, bind <functional>, bind2nd

<memory>, unique_ptr <memory>, auto_ptr

hash_map,map,unordered_map效率的更多相关文章

  1. hash_map vs unordered_map vs map vs unordered_set

    hash_map vs unordered_map 这两个的内部结构都是采用哈希表来实现.unordered_map在C++11的时候被引入标准库了,而hash_map没有,所以建议还是使用unord ...

  2. map、hash_map、unordered_map 的思考

    #include <map> map<string,int> dict; map是基于红黑树实现的,可以快速查找一个元素是否存在,是关系型容器,能够表达两个数据之间的映射关系. ...

  3. STL——map/unordered_map基础用法

    map /multimap map是STL里重要容器之一. 它的特性总结来讲就是:所有元素都会根据元素的键值key自动排序(也可根据自定义的仿函数进行自定义排序),其中的每个元素都是<key,  ...

  4. map,hash_map和unordered_map 实现比较

    map介绍 Map是STL[1]的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处 ...

  5. boost::unordered_map 和 std::map 的效率 与 内存比较

    例子链接:http://blog.csdn.net/gamecreating/article/details/7698719 结论: unordered_map 查找效率快五倍,插入更快,节省一定内存 ...

  6. hash_map map

    什么时候需要用hash_map,什么时候需要用map? 总体来说,hash_map 查找速度会比map快,而且查找速度基本和数据数据量大小,属于常数级别;而map的查找速度是log(n)级别.并不一定 ...

  7. c++ map unordered_map

    map operator<的重载一定要定义成const.因为map内部实现时调用operator<的函数好像是const. #include<string> #include& ...

  8. Map遍历效率比较

    1.由来 上次博客提到了Map的四种遍历方法,其中有的只是获取了key值或者是value值,但我们应该在什么时刻选择什么样的遍历方式呢,必须通过实践的比较才能看到效率. 也看了很多文章,大家建议使用e ...

  9. Map遍历效率 : entrySet > keySet

     1    //entrySet()  2     for (Entry<String, String> entry : map.entrySet()) {  3         Stri ...

随机推荐

  1. 六步教你如何用PADS进行PCB设计?

    在使用PADS进行PCB设计的过程中,需要对印制板的设计流程以及相关的注意事项进行重点关注,这样才能更好的为工作组中的设计人员提供系统的设计规范,同时也方便设计人员之间进行相互的交流和检查. 02 设 ...

  2. EasyX安装教程

    Easyx是什么 就是一款可以在Windows里让你的C++程序里显示图片等的工具. 注意:EasyX不支持Linux.MacOS.不过还有Qt等可以选择. 安装VC/VS Easyx只支持Visua ...

  3. 全志Linux Tina编译demoOmxVdec错误

    测试裸流 Making install in demoOmxVdec make[6]: Entering directory '/home/liuxueneng/WorkCode/Homlet-Tin ...

  4. 【网络好文】---MySQL为Null导致的四大坑

    正式开始之前,我们先来看下 MySQL 服务器的配置和版本号信息,如所示: select version(); -- 版本为 8.0.22 "兵马未动粮草先行",看完了相关的配置之 ...

  5. Oracle 相关命令

    http://www.mamicode.com/info-detail-2481866.html sql语句 system用户登陆 查看表空间和存放位置 select t1.name,t2.name ...

  6. Qt 窗口阴影效果的实现

    前言 今天正好搞一下窗口的阴影,发现一篇文章写的真是不错.毫不犹豫滴转过来了,感谢作者分享. 转自:http://blog.sina.com.cn/s/blog_a6fb6cc90101eoop.ht ...

  7. CVAT 用户指南

    用户指南 计算机视觉标注工具(CVAT)是基于 Web 为计算机视觉算法标注视频和图像的在线工具. 它的灵感来自Vatic免费的.在线的.交互式的视频注释工具. CVAT有许多强大的功能: 在关键帧之 ...

  8. JavaScript 对象:String & Array 及其常见应用

    String对象 split 功能:把字符串分割为字符串数组.官方文档已经描述的够清楚,不多赘述.主要说一下需要注意的情况以及应用 1.省略分割参数 var str="How are you ...

  9. 基于霸道秉火的STM32F103ZET6嵌入式开发之------定时器中断3

    1 #include "time.h" 2 #include "led.h" 3 #include "beep.h" 4 //¶¨Ê±Æ÷Ö ...

  10. 第九届网安竞赛writeup

    web easysql[已解决] uname=a') union select 1,extractvalue(1, concat(0x7e, (select database()),0x7e))#&a ...