MATLAB: Calculation speed

calculationdesktoplaptopperformancespeed

I tried making a very simple algorithm for testing the computers speed, like this
tic;
for r = 1:2000;
for c = 1:2000;
A(r,c) = r^2+sqrt(c);
end
end
toc
And it's obviously on purpose that I didn't preallocate A, since I want to stress the processor a bit. Anyway, i ran it on three different computers with follow results:
University desktop, with Ubuntu and Matlab 2010b. Time ~18 sek
Home desktop, with Windows and Matlab 2011 (i think). Time ~7 sek
Home laptop, with Ubuntu and Matlab 2011 or 2012 (dont remember) Time ~4 sek
The thing that confuses me a bit, is that my Laptop is that much faster than my home desktop, since both processor, graphics card and ram should be superior on the home desktop. Can anyone help me solve this mystery?

Best Answer

Filling an array without pre-allocation does not stress the processor, but the memory. Therefore the processor is most of the time in sleep mode during your program runs. Matlab's collaboration with the memory manager of Window 7 is obviously better than with the manager of Ubuntu.
Matlab 2012a uses a new technique to reduce the drawbacks of a missing pre-allocation. It seems, like it allocates memory in larger chunks predictively, buit I do not know any details.
Therefore your measurements are not surprising. If you need a more detailed answer, post the exact description of the used operating systems and Matlab versions (version numbers and 32/64 bits). In addition post the amount of installed and available RAM as well as the type and speed of the RAM.