linux下unordered_map和map在小数据下性能差异
来源:互联网 发布:cf英雄武器抽奖 软件 编辑:程序博客网 时间:2024/06/05 06:49
说起性能,没有测试,还是没有发言权:
#include <map>#include <boost/unordered_map.hpp>#include <string>#include <iostream>#include <sys/time.h>#include <stdio.h>#include <stdlib.h>#include <hash_map>#include <unordered_map>timeval g_ts;long getnow(){ gettimeofday(&g_ts, NULL); return g_ts.tv_usec;}int size = 10;int getrand(){ return rand()%size;}int main(int agr, char** argc){ if (agr < 2){ printf("uage gar < 2\n"); exit(1); } size = atoi(argc[1]); std::unordered_map<int, std::string> map1; long t1 = getnow(); for (int i = 0; i < size; ++i){ map1.insert(std::make_pair(getrand(),"tes")); } for(int i = 0; i < size; ++i){ map1.find(getrand()); } int rand1 = getrand(); for (int i = 0; i < size; ++i){ map1.erase(getrand()); } printf("unordered_map %d insert time:%ld\n", size, getnow()-t1); std::map<int, std::string> map2; t1 = getnow(); for(int i = 0; i < size; ++i){ map2.insert(std::make_pair(getrand(), "tes")); } for(int i = 0; i < size; ++i){ map2.find(getrand()); } for(int i = 0; i < size; ++i){ map2.erase(getrand()); } printf("std::map insert&find %d times use:%ld\n", size, getnow() - t1);}
输出结果为:allen@allenPC:~/code/c++code$ ./tetsb 10
unordered_map 10 insert time:44
std::map insert&find 10 times use:33
allen@allenPC:~/code/c++code$ ./tetsb 100
unordered_map 100 insert time:186
std::map insert&find 100 times use:212
allen@allenPC:~/code/c++code$ ./tetsb 200
unordered_map 200 insert time:330
std::map insert&find 200 times use:453
allen@allenPC:~/code/c++code$ ./tetsb 500
unordered_map 500 insert time:792
std::map insert&find 500 times use:1236
allen@allenPC:~/code/c++code$ ./tetsb 1000
unordered_map 1000 insert time:1552
std::map insert&find 1000 times use:2587
allen@allenPC:~/code/c++code$
看来还是如果数据量较小,unorderedmap更快!
0 0
- linux下unordered_map和map在小数据下性能差异
- Linux下map hash_map和unordered_map效率比较
- Linux下map hash_map和unordered_map效率比较
- Linux下map、hash_map和unordered_map效率比较
- Linux下map hash_map和unordered_map效率比较
- Linux下map、hash_map和unordered_map效率比较
- socket在linux和windows下的差异
- Oracle 下 1万和5万分批删除数据的性能差异
- Qt文件遍历在linux下和windows下的差异
- linux 下的差异和增量备份
- map、hash_map和unordered_map
- unordered_map和map
- unordered_map和map
- 关于map、hash_map 和 unordered_map 的简单性能测试
- map hash_map unordered_map 性能测试
- map hash_map unordered_map 性能测试
- map hash_map unordered_map 性能测试
- map hash_map unordered_map 性能测试
- NSArray打印对象
- I - Dirichlet's Theorem on Arithmetic Progressions(1.5.5)
- POJ3190 Stall Reservations 贪心
- uva 755(排序、检索)
- IT运维问道---文启
- linux下unordered_map和map在小数据下性能差异
- Linux内核通知链模块
- 加载gif图片
- c++基础浅谈一开始学习c++
- POJ 3660 Cow Contest(Floyd传递闭包)
- UE4学习笔记(四): 开发体验
- windows phone通过加载xaml动态创建控件
- 数字图像处理-空间域图像增强(二)(直方图)
- static_cast, dynamic_cast, const_cast探讨