Just now, I came to know that Matlab & Octave uses column-major from Wikipedia.
Column-major order is used in Fortran, OpenGL and OpenGL ES, MATLAB, GNU Octave, R, Julia, Rasdaman, and Scilab.
So I was just checking the "for loop" speed in both Matlab and Octave. Below are the results:
Matlab
>> x = rand(10000);
>> tic; for i=1:10000 for j=1:10000 k=x(i,j); end; end; toc; % row-major
Elapsed time is 2.320215 seconds.
>> tic; for i=1:10000 for j=1:10000 k=x(j,i); end; end; toc; % column-major
Elapsed time is 0.433013 seconds.
As expected, Column-major order is faster than row-major order.
Octave
> x=rand(5000);
> tic; for i=1:5000 for j=1:5000 k=x(i,j); end; end; toc; % row-major
Elapsed time is 77 seconds.
> tic; for i=1:5000 for j=1:5000 k=x(j,i); end; end; toc; % column-major
Elapsed time is 78 seconds.
The results are same in both the cases.
Question: Why both row-major and column-major looping perform similar in Octave, although it uses column-major alignment?