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



Re: matlab slow for loop
Posted:
Jan 8, 2013 2:24 AM


dpb <none@non.net> wrote in message <kcfm3s$h0q$1@speranza.aioe.org>...
> >> sum=0;t=1;tic,for i=1:10E5,sum=sum+t;end,toc > elapsed_time = > 1.0160 > >> sum=0;t=1;tic,for i=1:10E5,sum=sum+t;end,toc > elapsed_time = > 1.0160 > >> sum=0;t=1;tic,for i=1:10E5,sum=sum+t;end,toc > elapsed_time = > 1.0160 > >> which sum > sum is a variable. > >> >
I must yell now and then this kind of benchmark occurs due to 2 careless mistakes: 1) never benchmark a script > put it in a function 2) never scramble many statements in the same line
function testforloop thing=1; sum=0; tic for i=1:10E5 sum=sum+thing; end toc end
Only then, one can conclude something correct.
Bruno



