comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » FOR loops and efficiency
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: FOR loops and efficiency [message #66662 is a reply to message #66579] Wed, 27 May 2009 22:38 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On May 26, 5:51 pm, JDS <jdtsmith.nos...@yahoo.com> wrote:
>> I still stand by my rule of thumb.  The problem with FOR loops is the
>> amount of time spent doing loop overhead stuff.  If you run your loop
>> but *take all the calculations out*, and the total execution time is
>> not perceptible, then you probably won't gain by optimizing/
>> vectorizing.
>
> I find that analysis lacking for a few reasons.  Consider this
> example:
...
> IDL> t=systime(1) & for i=0L,10000000L-2 do a[i+1]+=a[i] &print,systime(1)-t
...
> IDL> t=systime(1) & for i=0L,10000000L-2 do begin & end & print,systime(1)-t
>       0.12700295
...
> Loop overhead is one reason to avoid FOR loops with high iteration
> count, but it is by no means not the *only* reason.  ...

I agree with everything you said. I still stand by my guideline as
rule of thumb to know when optimization is important. Note that the
rule of thumb didn't involve trying to compare the execution time of
an empty loop and a full loop. :-)

By the way, if you put a simple dummy statement like this,

t=systime(1) & for i=0L,10000000L-2 do begin & dummy = 0 & end &
print,systime(1)-t

Then the execution time is more like 0.5 seconds. While I agree that
this is not the same as 2.2 seconds, it is definitely more
comparable.

Craig
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: surface_polar plot
Next Topic: Re: Using FFT convolve() : centering error?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:08:11 PDT 2025

Total time taken to generate the page: 0.00407 seconds