here is a simple code that shows it:
function c=myfunc(a,b)c=a*b;function c=main_temp()a(1)=5;a(2)=8;r=1e7;ticfor i=1:r c=myfunc(a(1),a(2));endtocticfor i=1:r c=a(1)*a(2);endtocend
here is the timing using tic-toc
Elapsed time is 0.327171 seconds.
Elapsed time is 0.009264 seconds.
it's about 40 times slower (for no apparent reason except function overheads). and it gets much worse when using classes (about 15 times slower then the function call).
i searched extensively around the web and read every performance post and guidances related post.
also, this is a very very simple code that shows a core problem.
Best Answer