C++拾趣——STL容器的插入、删除、遍历和查找操作性能对比(Windows VirtualStudio)——遍历和删除

栏目: C++ · 发布时间: 7年前

内容简介:性能最差的是map、multimap、set和multiset这两簇。其他容器性能差距不大。非关联容器中,list的性能最差。

遍历

从前往后

C++拾趣——STL容器的插入、删除、遍历和查找操作性能对比(Windows VirtualStudio)——遍历和删除
traversal_begin_16384_highest

性能最差的是map、multimap、set和multiset这两簇。

其他容器性能差距不大。

非关联容器中,list的性能最差。

从后往前

支持从后向前遍历的容器并不多,只有:vector、deque、list、set、map、multiset和multimap。

元素个数>15000

C++拾趣——STL容器的插入、删除、遍历和查找操作性能对比(Windows VirtualStudio)——遍历和删除
traversal_end_16384_highest

非关联容器的性能要优于关联容器。

非关联容器之间相比,性能差距不大。

在12500个元素之前,vector的效率要比list和deque低,但是之后vector是最优的。

元素个数<4096

C++拾趣——STL容器的插入、删除、遍历和查找操作性能对比(Windows VirtualStudio)——遍历和删除
traversal_end_4096_highest

vector在初期会有高耗时操作,之后性能优秀(通过斜率)。

结论:

除了map、multimap、set和multiset,其他容器的遍历性能都差不了太多。

查找

因为非关联容器的查找只能通过遍历,其效率和关联容器的查找没法比。所以我们只比较关联容器。

元素个数>15000

C++拾趣——STL容器的插入、删除、遍历和查找操作性能对比(Windows VirtualStudio)——遍历和删除
find_16384_highest

set类要优于对应的map类容器。即set优于map;multiset优于multimap;unordered_set优于unordered_map;unordered_multiset优于unordered_multimap。

multi类要优于对应的非multi类容器。即multimap优于map;multiset优于set;unordered_multimap优于unordered_map;unordered_multiset优于unordered_set。

无序关联容器要优于有序关联容器。

文中图例可从如下地址获取: https://github.com/f304646673/stl_perf/tree/master/windows


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Nature of Code

The Nature of Code

Daniel Shiffman / The Nature of Code / 2012-12-13 / GBP 19.95

How can we capture the unpredictable evolutionary and emergent properties of nature in software? How can understanding the mathematical principles behind our physical world help us to create digital w......一起来看看 《The Nature of Code》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试