May too many register variables hurt? (was Re: Novice question.)
Richard Caley
rjc at uk.ac.ed.cstr
Thu Nov 29 12:27:24 AEST 1990
In article <9733:Nov2722:02:3090 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
In typical programs, some variables are used quite
a lot, and they should be declared register. Some variables are rarely
used, and they shouldn't be declared register. It's better to err on the
side of extra register declarations than to pessimize your code in the
common case.
IMHO, it is better not to declare register variabes unless you need to
(i.e. the code won't perform as needed without). Given
void
tweakit(register struct foobar *lastone)
{
}
vs.
void
tweakit(struct foobar *lastone)
{
}
I find the second _so_ much more readable that adding in the register
for, say, a 10% speedup in a program which runs in 10 seconds is not
worth it unless you are _very_ sure that that second is critical and
the code is more or less totally stable.
If the time _is_ critical then it is not enough to stick in a few
register variables anyway, it is time to wheel out the profiler, stare
at the assembler output and work out whether floating point arithmetic
or jumps are more time critical on your machine.
--
rjc at uk.ac.ed.cstr real men don't use typedefs!
More information about the Comp.lang.c
mailing list