Boost::multi_array performance question

前端 未结 16 2034
不思量自难忘°
不思量自难忘° 2020-12-04 11:20

I am trying to compare the performance of boost::multi_array to native dynamically allocated arrays, with the following test program:

#include 

        
相关标签:
16条回答
  • 2020-12-04 12:13

    Build in release mode, use objdump, and look at the assembly. They may be doing completely different things, and you'll be able to see which optimizations the compiler is using.

    0 讨论(0)
  • 2020-12-04 12:16

    I would have expected multiarray to be just as efficient. But I'm getting similar results on a PPC Mac using gcc. I also tried multiarrayref, so that both versions were using the same storage with no difference. This is good to know, since I use multiarray in some of my code, and just assumed it was similar to hand-coding.

    0 讨论(0)
  • 2020-12-04 12:17

    Another thing to try is to use iterators instead of a straight index for the boost array.

    0 讨论(0)
  • 2020-12-04 12:17

    Looking at the assembly generated by g++ 4.8.2 with -O3 -DBOOST_DISABLE_ASSERTS and using both the operator() and the [][] ways to access elements, it's evident that the only extra operation compared to native arrays and manual index calculation is the addition of the base. I didn't measure the cost of this though.

    0 讨论(0)
提交回复
热议问题