Boost::multi_array performance question

前端 未结 16 2165
不思量自难忘°
不思量自难忘° 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 11:57

    Your test is flawed.

    • In a DEBUG build, boost::MultiArray lacks the optimization pass that it sorely needs. (Much more than a native array would)
    • In a RELEASE build, your compiler will look for code that can be removed outright and most of your code is in that category.

    What you're likely seeing is the result of your optimizing compiler seeing that most or all of your "native array" loops can be removed. The same is theoretically true of your boost::MultiArray loops, but MultiArray is probably complex enough to defeat your optimizer.

    Make this small change to your testbed and you'll see more true-to-life results: Change both occurances of "= 2.345 " with "*= 2.345 " and compile again with optimizations. This will prevent your compiler from discovering that the outer loop of each test is redundant.

    I did it and got a speed comparison closer to 2:1.

提交回复
热议问题