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

Home » Public Forums » archive » Re: 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 #66616 is a reply to message #66542] Fri, 22 May 2009 11:24 Go to previous message
Christopher Thom is currently offline  Christopher Thom
Messages: 66
Registered: October 2006
Member
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?

cheers
chris

ps -- Also...I'm aware that "premature optimisation is the root of all
evil", according to knuth...
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Is a dynamically sized pointer array object component possible?
Next Topic: Transporting code from one mac to another: Problem connection to X windows server...

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

Current Time: Sun Apr 26 20:47:46 PDT 2026

Total time taken to generate the page: 1.51906 seconds