  data = rand(5000,5000); % 25M elements, 200MB = 50 K memory pages
  % Row-first loop (natural order, bad for performance)
total = 0;
tic;
for rowIdx = 1:size(data,1)
    for colIdx = 1:size(data,2)
        total = total + data(rowIdx,colIdx);
    end
end
toc

%% Column-first loop (less natural, but much better performance)
total = 0;
tic
for colIdx = 1:size(data,2) 
    for rowIdx = 1:size(data,1)
        total = total + data(rowIdx,colIdx);
    end
end
toc