Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: matlab slow for loop
Replies: 9   Last Post: Jan 8, 2013 5:46 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruno Luong

Posts: 8,847
Registered: 7/26/08
Re: matlab slow for loop
Posted: Jan 8, 2013 2:24 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.