Boost::multi_array performance question

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

    On my machine using

    g++ -O3 -march=native -mtune=native --fast-math -DNDEBUG test.cpp -o test && ./test
    

    I get

    [Boost] Elapsed time:  0.020 seconds
    [Native]Elapsed time:  0.020 seconds
    

    However changing const int ITERATIONS to 5000 I get

    [Boost] Elapsed time:  0.240 seconds
    [Native]Elapsed time:  0.180 seconds
    

    then with ITERATIONS back to 500 but X_SIZE and Y_SIZE set to 400 I get a much more significant difference

    [Boost] Elapsed time:  0.460 seconds
    [Native]Elapsed time:  0.070 seconds
    

    finally inverting the inner loop for the [Boost] case so it looks like

        for (int x = 0; x < X_SIZE; ++x)
        {
            for (int y = 0; y < Y_SIZE; ++y)
            {
    

    and keeping ITERATIONS, X_SIZE and Y_SIZE to 500, 400 and 400 I get

    [Boost] Elapsed time:  0.060 seconds
    [Native]Elapsed time:  0.080 seconds
    

    If I invert the inner loop also for the [Native] case (so it is in the wrong order for that case), I get, unsurprisingly,

    [Boost] Elapsed time:  0.070 seconds
    [Native]Elapsed time:  0.450 seconds
    

    I am using gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 on Ubuntu 10.10

    So in conclusion:

    • With proper optimization boost::multi_array does its job as expected
    • The order on which you access your data does matter

提交回复
热议问题