title: Why is MATLAB so fast in matrix multiplication?
body: <p>I am making some benchmarks with CUDA, C++, C#, Java, and using MATLAB for verification and matrix generation.  When I perform matrix multiplication with MATLAB, <code>2048x2048</code> and even bigger matrices are almost instantly multiplied.</p>
  <pre class="lang-none prettyprint-override"><code>             1024x1024   2048x2048   4096x4096
               ---------   ---------   ---------
  CUDA C (ms)      43.11      391.05     3407.99
  C++ (ms)       6137.10    64369.29   551390.93
  C# (ms)       10509.00   300684.00  2527250.00
  Java (ms)      9149.90    92562.28   838357.94
  MATLAB (ms)      75.01      423.10     3133.90
  </code></pre>
  <p>Only CUDA is competitive, but I thought that at least C++ will be somewhat close and not 60 times slower. I also don't know what to think about the C# results. The algorithm is just the same as C++ and Java, but there's a giant jump <code>2048</code> from <code>1024</code>.</p>
  <p>How is MATLAB performing matrix multiplication so fast?</p>
  <p>C++ Code:</p>
  <pre class="lang-cpp prettyprint-override"><code>float temp = 0;
  timer.start();
  for(int j = 0; j &lt; rozmer; j++)
  {
      for (int k = 0; k &lt; rozmer; k++)
      {
          temp = 0;
          for (int m = 0; m &lt; rozmer; m++)
          {
              temp = temp + matice1[j][m] * matice2[m][k];
          }
          matice3[j][k] = temp;
      }
  }
  timer.stop();
  </code></pre>