title: Compare blitz++, armadillo, boost::MultiArray
body: <p>I did a comparison between blitz++, armadillo, boost::MultiArray with the following code (borrowed from <a href="https://stackoverflow.com/questions/446866/boostmulti-array-performance-question/539001#539001">an old post</a>)</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  #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;
  #include &lt;armadillo&gt;
  
  int main(int argc, char* argv[])
  {
      const int X_SIZE = 1000;
      const int Y_SIZE = 1000;
      const int ITERATIONS = 100;
      unsigned int startTime = 0;
      unsigned int endTime = 0;
  
      // Create the boost array
  
  
      //------------------Measure boost Loop------------------------------------------
      {
          typedef boost::multi_array&lt;double, 2&gt; ImageArrayType;
          ImageArrayType boostMatrix(boost::extents[X_SIZE][Y_SIZE]);
          startTime = ::GetTickCount();
          for (int i = 0; i &lt; ITERATIONS; ++i)
          {
              for (int x = 0; x &lt; X_SIZE; ++x)
              {
                  for (int y = 0; y &lt; Y_SIZE; ++y)
                  {
                      boostMatrix[x][y] = 1.0001;
                  }
              }
          }
          endTime = ::GetTickCount();
          printf("[Boost Loop] Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0);
      }
      //------------------Measure blitz Loop-------------------------------------------
      {
          blitz::Array&lt;double, 2&gt; blitzArray( X_SIZE, Y_SIZE );
          startTime = ::GetTickCount();
          for (int i = 0; i &lt; ITERATIONS; ++i)
          {
              for (int x = 0; x &lt; X_SIZE; ++x)
              {
                  for (int y = 0; y &lt; Y_SIZE; ++y)
                  {
                      blitzArray(x,y) = 1.0001;
                  }
              }
          }
          endTime = ::GetTickCount();
          printf("[Blitz Loop] Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0);
      }
  
      //------------------Measure armadillo loop----------------------------------------
      {
          arma::mat matArray( 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)
                  {
                      matArray(x,y) = 1.0001;
                  }
              }
          }
          endTime = ::GetTickCount();
          printf("[arma  Loop]  Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0);
      }
  
      //------------------Measure native loop----------------------------------------
      // 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*X_SIZE; ++y)
              {
                  nativeMatrix[y] = 1.0001;
              }
          }
          endTime = ::GetTickCount();
          printf("[Native Loop]Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0);
          delete[] nativeMatrix;
      }
  
      //------------------Measure boost computation-----------------------------------
      {
          typedef boost::multi_array&lt;double, 2&gt; ImageArrayType;
          ImageArrayType boostMatrix(boost::extents[X_SIZE][Y_SIZE]);
          for (int x = 0; x &lt; X_SIZE; ++x)
          {
              for (int y = 0; y &lt; Y_SIZE; ++y)
              {
                  boostMatrix[x][y] = 1.0001;
              }
          }
          startTime = ::GetTickCount();
          for (int i = 0; i &lt; ITERATIONS; ++i)
          {
              for (int x = 0; x &lt; X_SIZE; ++x)
              {
                  for (int y = 0; y &lt; Y_SIZE; ++y)
                  {
                      boostMatrix[x][y] += boostMatrix[x][y] * 0.5;
                  }
              }
          }
          endTime = ::GetTickCount();
          printf("[Boost computation] Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0);
      }
  
      //------------------Measure blitz computation-----------------------------------
      {
          blitz::Array&lt;double, 2&gt; blitzArray( X_SIZE, Y_SIZE );
          blitzArray = 1.0001;
          startTime = ::GetTickCount();
          for (int i = 0; i &lt; ITERATIONS; ++i)
          {
              blitzArray += blitzArray*0.5;
          }
          endTime = ::GetTickCount();
          printf("[Blitz computation] Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0);
      }
  
      //------------------Measure armadillo computation-------------------------------
      {
          arma::mat matArray( X_SIZE, Y_SIZE );
          matArray.fill(1.0001);
          startTime = ::GetTickCount();
          for (int i = 0; i &lt; ITERATIONS; ++i)
          {
              //matArray.fill(1.0001);
              matArray += matArray*0.5;
          }
          endTime = ::GetTickCount();
          printf("[arma  computation] Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0);
      }
  
      //------------------Measure native computation------------------------------------------
      // Create the native array
      {
          double *nativeMatrix = new double [X_SIZE * Y_SIZE];
          for (int y = 0; y &lt; Y_SIZE*X_SIZE; ++y)
          {
              nativeMatrix[y] = 1.0001;
          }
          startTime = ::GetTickCount();
          for (int i = 0; i &lt; ITERATIONS; ++i)
          {
              for (int y = 0; y &lt; Y_SIZE*X_SIZE; ++y)
              {
                  nativeMatrix[y] += nativeMatrix[y] * 0.5;
              }
          }
          endTime = ::GetTickCount();
          printf("[Native computation]Elapsed time: %6.3f seconds\n", (endTime - startTime) / 1000.0);
          delete[] nativeMatrix;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>On windows, VS2010, results are</p>
  
  <pre><code>[Boost Loop] Elapsed time:  1.217 seconds
  [Blitz Loop] Elapsed time:  0.046 seconds
  [arma  Loop]  Elapsed time:  0.078 seconds
  [Native Loop]Elapsed time:  0.172 seconds
  [Boost computation] Elapsed time:  2.152 seconds
  [Blitz computation] Elapsed time:  0.156 seconds
  [arma  computation] Elapsed time:  0.078 seconds
  [Native computation]Elapsed time:  0.078 seconds
  </code></pre>
  
  <p>On windows, intel c++, results are</p>
  
  <pre><code>[Boost Loop] Elapsed time:  0.468 seconds
  [Blitz Loop] Elapsed time:  0.125 seconds
  [arma  Loop]  Elapsed time:  0.046 seconds
  [Native Loop]Elapsed time:  0.047 seconds
  [Boost computation] Elapsed time:  0.796 seconds
  [Blitz computation] Elapsed time:  0.109 seconds
  [arma  computation] Elapsed time:  0.078 seconds
  [Native computation]Elapsed time:  0.062 seconds
  </code></pre>
  
  <p>Something strange: </p>
  
  <pre><code>(1) with VS2010, native computation (including loop) is faster than native loop
  (2) blitz loop behave so different under VS2010 and intel C++. 
  </code></pre>
  
  <p>To compile blitz++ with intel c++ compiler, a file called bzconfig.h is required in blitz/intel/ folder. But there isn't. I just copy the one in blitz/ms/bzconfig.h in. That may give an non-optimal configuration. Anyone can tell me how to compile blitz++ with intel c++ compiler? In the manual, it said run bzconfig script to get the right bzconfig.h. But I don't understand what it means.</p>
  
  <p>Thanks a lot!</p>
  
  <p>Add some of my conclusion:</p>
  
  <pre><code>1. Boost multi array is the slowest.
  2. With intel c++ compiler, native pointers are very fast.
  3. With intel c++ compiler,  armadillo can achieve the performance of native pointers.
  4. Also test eigen, it is x0% slower than armadillo in my simple cases.
  5. Curious about blitz++'s behavior in intel c++ compiler with proper configuration.
     Please see my question.
  </code></pre>