title: Time comparison of "for" loop in Matlab and Octave
body: <p>Just now, I came to know that Matlab &amp; Octave uses column-major from <a href="http://en.wikipedia.org/wiki/Row-major_order" rel="nofollow">Wikipedia</a>.</p>
  
  <blockquote>
    <p>Column-major order is used in Fortran, OpenGL and OpenGL ES, MATLAB,
    GNU Octave, R, Julia, Rasdaman, and Scilab.</p>
  </blockquote>
  
  <p>So I was just checking the "for loop" speed in both Matlab and Octave. Below are the results:</p>
  
  <p><strong>Matlab</strong></p>
  
  <pre><code>&gt;&gt; x = rand(10000);
  &gt;&gt; tic; for i=1:10000 for j=1:10000 k=x(i,j); end; end; toc; % row-major
  Elapsed time is 2.320215 seconds.
  &gt;&gt; tic; for i=1:10000 for j=1:10000 k=x(j,i); end; end; toc; % column-major
  Elapsed time is 0.433013 seconds.
  </code></pre>
  
  <p>As expected, <strong>Column-major order is faster than row-major order.</strong></p>
  
  <p><strong>Octave</strong></p>
  
  <pre><code>&gt; x=rand(5000);
  &gt; tic; for i=1:5000 for j=1:5000 k=x(i,j); end; end; toc; % row-major
  Elapsed time is 77 seconds.
  &gt; tic; for i=1:5000 for j=1:5000 k=x(j,i); end; end; toc; % column-major
  Elapsed time is 78 seconds.
  </code></pre>
  
  <p><strong>The results are same in both the cases.</strong></p>
  
  <p><strong>Question:</strong>
  Why both row-major and column-major looping perform similar in Octave, although it uses column-major alignment?</p>