Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Vectorized Code: *Why* it works..?
Posted:
Apr 26, 2013 9:10 PM


On 4/26/2013 7:04 PM, Loki wrote: > > Vecorized code is tremedously faster when compared to nonvectorized > code. > > Why is so? Reason lies only in CPU vector instructions that matlab > uses internally when execute vetorized code, or there are other > reasons? > > To find more informations via google is strangely difficult. >
In here
http://www.mathworks.com/help/matlab/matlab_prog/techniquesforimprovingperformance.html
It just says
"Vectorize your code to take advantage of the full functionality of MATLAB."
But if you follow the link to
http://www.mathworks.com/help/matlab/matlab_prog/vectorization.html
"Performance: Vectorized code often runs much faster than the corresponding code containing loops."
as to WHY vectorized code is faster, well, I think only person who can answer this for sure, is someone working inside Matlab, in the runtime/compiler group.
But simply googling "matlab why is vectorized faster" I see many well reasoned answers there all over the web on this. I only see sites showing that vectorized code is not always faster the loops. I seem to remember that few years ago MW did improvement to their jit compiler to improve loop speeds, so the difference is not that much. I would guess it depend on the code being processed each time.
Nasser



