help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About g++ optimization


From: Andre Poenitz
Subject: Re: About g++ optimization
Date: Sat, 1 Apr 2006 14:14:59 +0200

rmansfield@gmail.com <rmansfield@gmail.com> wrote:
> If your f() returns a constant, your best bet is to do:
> 
> for (int i =0,  j = f(n); i < j; ++i) {
> }

Or if it doen't matter in what order the iteration is performed,
even

 for (int i = f(n); i--; )

might do. (Note the i-- is post-decrement and in the 'test' position)

Saves usually a register and replaces a check against an 'arbitrary'
number with a check for zero (which is faster/smaller on some
architectures).

Of course, this won't work when you can't invert the iteration order.

Andre'


reply via email to

[Prev in Thread] Current Thread [Next in Thread]