Re: Inherent inefficiency in domestic "for" loop?
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 26 Jun 2006 00:48:30 GMT
In article <Xns97EED4FE9B37fgothamNOSPAM@xxxxxxxxxxxxxx>,
Frederick Gotham <fgothamNO@xxxxxxxx> wrote:
Yes, exactly. But about 90% of the time, we're dealing with a loop which
will always execute at least once.
I just grepped the for loops in a fairly substantial piece of code
that I wrote. About a third of the for loops can execute zero times.
But almost all of the loops that execute at least once are
initializing data, and are only executed once each. So the proportion
of at-least-once loops executed is probably very small.
For this 90% of the time, there's one
extra redudant evaluation performed.
The vast majority of the at-least-once loops were cases where the
initial value and the valued tested against were constant, so the
compiler can generate code that tests at the end if that is more
efficient. Don't assume that something is inefficient without
considering how it can be implemented.
I don't think the "for" loop should have been shaped to accomodate the 10%
of the time where we might not want the loop to run at all.
Perhaps the authors of C had a better insight into what the common case
is and what the costs are.
-- Richard
.
- References:
- Inherent inefficiency in domestic "for" loop?
- From: Frederick Gotham
- Re: Inherent inefficiency in domestic "for" loop?
- From: Gordon Burditt
- Re: Inherent inefficiency in domestic "for" loop?
- From: Frederick Gotham
- Inherent inefficiency in domestic "for" loop?
- Prev by Date: Re: beginner c question
- Next by Date: Problem in compiling a C code with MSVC++6.00
- Previous by thread: Re: Inherent inefficiency in domestic "for" loop?
- Next by thread: Re: Inherent inefficiency in domestic "for" loop?
- Index(es):
Relevant Pages
|