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 #66609 is a reply to message #66568] Sat, 23 May 2009 13:24 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On May 22, 2:24 pm, Christopher Thom <ct...@oddjob.uchicago.edu>
wrote:
> Quoth Craig Markwardt:
>
>> A FOR loop will only be slow(er) when the time spent executing the
>> loop overhead is much more than the time spent doing the computations
>> in one loop iteration.  A simple test would be to execute a dummy
>> loop:
>>   NMAX = 100000L
>>   FOR I = 0L, NMAX do begin & dummy = 1
>> Keep raising the value of NMAX until the execute time of the loop is
>> perceptible.  Don't bother trying to optimize loops smaller than this.
>
>> In your case, you are only doing ten iterations, and each iteration
>> does a lot of work, so you won't gain by removing the loop.
>
> I've heard this description about FOR loops a lot, but one general
> question I've never been able to answer is, "how do i know when my loops
> are doing enough work?". How do I know when my loop overhead is a large
> fraction of the time spent on an iteration?
>
> I guess the real underlying question here is recognising when to optimise,
> and when to simply move on to more important things. Does anyone have any
> rules of thumb to help guide this recognition?

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.

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 17:54:14 PDT 2025

Total time taken to generate the page: 0.00445 seconds