Hello. The question is this. Why are the same code executed at different speeds in different versions of matlab? Versions 2014b and 2017a.
Below are screenshots with the difference in code execution in different versions.
I noticed one strange thing. If I write code without declaring a function, then the difference in execution between versions is huge.
If the code is described as a function, then speed is greatly increased
code without declaring a function:
clearb = rand(1000000,10);i=1;ticwhile i <= 1000res = b(:,1).*b(:,10);i = i+1;endtoc
result Matlab 2014b :
Elapsed time is 1.962136 seconds.
result Matlab 2017a :
Elapsed time is 8.741258 seconds.
code with function:
function f=Untitledclearb = rand(1000000,10);i=1;ticwhile i <= 1000res = b(:,1).*b(:,10);i = i+1;endtocend
result Matlab 2014b :
Elapsed time is 1.757147 seconds.
result Matlab 2017a :
Elapsed time is 1.885382 seconds.
p.s. Untitled is the name of the script / function
Best Answer