Message-ID: <337AE3CB.41ED@silesia.top.pl> Date: Thu, 15 May 1997 12:22:03 +0200 From: Michal MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Re: Any tips on optimizing C code? References: <33775c59 DOT 19219875 AT news DOT cis DOT yale DOT edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk 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).