哪个最快?boost :: multi_array还是std :: vector? [英] Which is the fastest? A boost::multi_array or a std::vector?

查看:132
本文介绍了哪个最快?boost :: multi_array还是std :: vector?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个最快?是 boost :: multi_array 还是 std :: vector ?我将拥有(不是常数)以3维存储的17.179.869元素,这些元素需要非常快速且非常频繁地在 for 循环内进行访问.表现最好的是什么?是 std :: vector 还是 boost :: multi_array ?

Which is the fastest? A boost::multi_array or a std::vector? I will have (not constant) 17.179.869 elements stored in 3 dimensions which will need to be accessed inside a for loop very rapidly and very often. What would be the most performing? An std::vector or a boost::multi_array?

(我不希望它能在一秒钟内完成,但我想使其尽可能高效,因为相差一纳秒可以节省大量时间.)

(I don't expect it to be done within a second, but I would like to have it as efficient as possible because a nanosecond difference can save a lot of time.)

推荐答案

最好的建议是自己进行基准测试.

Best advice is to benchmark it by yourself.

在任何情况下,由于您似乎都具有恒定的大小,因此还有其他解决方案:

In any case, since you seem to have constant size there are other solutions:

  • 普通C数组(例如 int数据[X] [Y] [Z] )
  • 使用一维C数组来自己计算索引,例如 X * W * H + Y * W + Z ,在某些情况下会很方便
  • std :: array ,它基本上是一个C ++数组,带有一些STL集合中的合规糖
  • std :: vector ,我猜这是可以尝试的第一个解决方案
  • boost :: multi_array ,它旨在支持N维数组,因此出于您的目的可能会显得过分杀伤,但与向量相比,它的数据局部性更好.
  • plain C arrays (eg. int data[X][Y][Z])
  • plain one dimensional C array in which you compute indices by yourself, eg X*W*H + Y*W + Z, can be handy in some situations
  • std::array, which is basically a C++ array with some synctactic sugar taken from STL collections
  • std::vector, which I guess is the first solution that can be tried
  • boost::multi_array, which is meant to support N dimensional arrays so it can be overkill for your purpose but probably has a better locality of data compared to a vector.

这篇关于哪个最快?boost :: multi_array还是std :: vector?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆