MATLAB: The Flop (Floating Point Operations per Second) Rate of MATLAB Code

flopsMATLABperformance

Hello, I know Intel MKL / IPP libraries performance in simple operations (Multiplication, Summation, Matrix Multiplication, Vector Multiplication) gets something like 80-95% of the theoretical performance of the CPU (Measured in FLOPS).
Yet, doing so using MATLAB I get much worse results.
I have this simple script:
numElements = 2 ^ 16;
numIter = 100;
vecX = randn(numElements, 1, 'single');
vecY = randn(numElements, 1, 'single');
initTime = tic();
for ii = 1:numIter
vecX .* vecY;
end
stopTime = toc(initTime);
gFlops = (numElements * numIter) / stopTime
Yet I get only 1.1 GFLOPS on my i7-860 Which should be closer to 2.8GHz (Frequency) * 4 (Cores) * 4 (Single Precisio Operations per Cycle as SSE Vector – 128 Bit) = 44.8 GFLOPS.
Yet I get something like 1.4 GFLOPS. Which is only 3% of the theoretical performance.
How can MATLAB be so inefficient?

Best Answer

I don't think the way you're trying to calculate flops here is right. Even if one assumes that you can calculate Flops like this, you're missing out many overheads that matlab is doing. For example, try something like this:
numElements = 2 ^ 18;
numIter = 100;
vecX = randn(numElements, 1, 'single');
vecY = randn(numElements, 1, 'single');
initTime = tic();
% for ii = 1:numIter
% vecX .* vecY;
% end
vecX + vecY; % I used +, but you can switch to .* as well
stopTime = toc(initTime);
gFlops = (numElements * numIter) / stopTime
And see if you see any difference. I am pretty sure you will. Remember, for loop is slow.