Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Consider using Blitz++ instead. I tried out Blitz, and its performance is on par with C-style array! </p> <p>Check out your code with Blitz added below:</p> <hr> <pre><code>#include &lt;windows.h&gt; #define _SCL_SECURE_NO_WARNINGS #define BOOST_DISABLE_ASSERTS #include &lt;boost/multi_array.hpp&gt; #include &lt;blitz/array.h&gt; int main(int argc, char* argv[]) { const int X_SIZE = 200; const int Y_SIZE = 200; const int ITERATIONS = 500; unsigned int startTime = 0; unsigned int endTime = 0; // Create the boost array typedef boost::multi_array&lt;double, 2&gt; ImageArrayType; ImageArrayType boostMatrix(boost::extents[X_SIZE][Y_SIZE]); //------------------Measure boost---------------------------------------------- startTime = ::GetTickCount(); for (int i = 0; i &lt; ITERATIONS; ++i) { for (int y = 0; y &lt; Y_SIZE; ++y) { for (int x = 0; x &lt; X_SIZE; ++x) { boostMatrix[x][y] = 2.345; } } } endTime = ::GetTickCount(); printf("[Boost] Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0); //------------------Measure blitz----------------------------------------------- blitz::Array&lt;double, 2&gt; blitzArray( X_SIZE, Y_SIZE ); startTime = ::GetTickCount(); for (int i = 0; i &lt; ITERATIONS; ++i) { for (int y = 0; y &lt; Y_SIZE; ++y) { for (int x = 0; x &lt; X_SIZE; ++x) { blitzArray(x,y) = 2.345; } } } endTime = ::GetTickCount(); printf("[Blitz] Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0); //------------------Measure native----------------------------------------------- // Create the native array double *nativeMatrix = new double [X_SIZE * Y_SIZE]; startTime = ::GetTickCount(); for (int i = 0; i &lt; ITERATIONS; ++i) { for (int y = 0; y &lt; Y_SIZE; ++y) { for (int x = 0; x &lt; X_SIZE; ++x) { nativeMatrix[x + (y * X_SIZE)] = 2.345; } } } endTime = ::GetTickCount(); printf("[Native]Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0); return 0; } </code></pre> <hr> <p>Here's the result in debug and release.</p> <p>DEBUG: </p> <pre><code>Boost 2.093 secs Blitz 0.375 secs Native 0.078 secs </code></pre> <p>RELEASE:</p> <pre><code>Boost 0.266 secs Blitz 0.016 secs Native 0.015 secs </code></pre> <p>I used MSVC 2008 SP1 compiler for this.</p> <p>Can we now say good-bye to C-stlye array? =p</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload