vector<> VS <> deque<> VS list<>

Here is the summary from an interesting performance benchmark article which comparing vector and list int C++11

Conclusion for vector<> VS deque<> VS list<>:

To conclude, we can get some facts about each data structure:

  • std::list is very very slow to iterate through the collection due to its very poor spatial locality.
  • std::vector and std::deque perform always faster than std::list with very small data
  • std::list handles very well large elements
  • std::deque performs better than a std::vector for inserting at random positions (especially at the front, which is constant time)
  • std::deque and std::vector do not support very well data types with high cost of copy/assignment

This draw simple conclusions on usage of each data structure:

  • Number crunching: use std::vector or std::deque
  • Linear search: use std::vector or std::deque
  • Random Insert/Remove: use std::list (if data size very small (< 64B on my computer), use std::deque)
  • Big data size: use std::list (not if intended for searching)
  • Non-trivial data type: use std::list
  • Push to front: use std::deque or std::list
Updated conclusion for vector<> VS list<>:
  • std::vector is insanely faster than std::list to find an element
  • std::vector performs always faster than std::list with very small data
  • std::vector is always faster to push elements at the back than std::list
  • std::list handles very well large elements, especially for sorting or inserting in the front

This draw simple conclusions on usage of each data structure:

  • Number crunching: use std::vector
  • Linear search: use std::vector
  • Random Insert/Remove: use std::list (if data size very small (< 64B on my computer), use std::vector)
  • Big data size: use std::list (not if intended for searching)

Reference:
http://www.baptiste-wicht.com/2012/11/cpp-benchmark-vector-vs-list/
http://www.baptiste-wicht.com/2012/12/cpp-benchmark-vector-list-deque/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值