Mail Archives: djgpp/1997/05/15/06:23:27
jon wrote:
>
> I'm interested in understanding what can be done to speed up straight
> C code. In the specific thing I am writing, I've already done the
> obvious things, like switched most calcs from FP to integer, using bit
> shifting wherever possible for multiplying and dividing, etc. But is
> there a complied source of information on just
> what-is-faster-than-what? Like, does running a "for" loop by
> decrementing rather than incrementing actually save a cycle? or does a
> "case" command actually beat a series of "if"s? Do global variable
> speed things up? I figure there must be something out there that has
> the low-down on just this sort of nitty-gritty info.
>
> DJGPP is my compiler of choice, if that makes a difference.
Use local variables as offen as you can, they are kept on stack and
becouse of thet are more likely to be in cache. Global variables are
usefull only in some cases, for example when your program does lots of
operations on the same variables (memory addresses) one after another -
try to organize your program in that way.
Use pointers to access memory structures, do not copy them unless it's
nesesery (for example when passing as an argument to a function).
- Raw text -