delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/15/06:23:27

Message-ID: <337AE3CB.41ED@silesia.top.pl>
Date: Thu, 15 May 1997 12:22:03 +0200
From: Michal <wapex AT silesia DOT top DOT pl>
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>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019