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

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

内容简介:性能最差的是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


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

查看所有标签

猜你喜欢:

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

New Dark Age

New Dark Age

James Bridle / Verso Books / 2018-7-17 / GBP 16.99

As the world around us increases in technological complexity, our understanding of it diminishes. Underlying this trend is a single idea: the belief that our existence is understandable through comput......一起来看看 《New Dark Age》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

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

正则表达式在线测试