delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/13/13:49:27

From: "quark(particle)" <quark AT webspan DOT net>
Newsgroups: comp.os.msdos.djgpp,rec.games.programmer
Subject: Re: Any tips on optimizing C code?
Date: 13 May 1997 12:36:15 EDT
Organization: WebSpan Inc., New Jersey
Message-ID: <5la59v$11b@news.webspan.net>
References: <33775c59 DOT 19219875 AT news DOT cis DOT yale DOT edu>
NNTP-Posting-Host: usr5-13.bay.ny.webspan.net
Lines: 54
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

if you're writing in DJGPP,, try compiling it with
gcc -O yoursource.c -o exename.exe

It can actually give you a real boost in performance...

if you're working with some piece of mem a lot... lock it in
memory.  use as less system calls a possible.  

If you simply need malloc, try creating a function like malloc
which will work with your previously allocated memory, and is 
faster than malloc.  I've seen this done in some prorgram, and 
it looks really descent.

try to find a better way to do something... look for the algorithmic 
approach... most things.. (people don't realize) can be done
with no divisions and no mults, and no shifts, and no floting 
point math... (I wrote a poligon fill without any of this stuff.)

try to unroll the loops... but be carefull, on modern systems, it can
actually decrease performance... but if the loop is small... say something
 like
for(int i=0;i<3;i++).. then unrolling it would be much faster.

case statements use exactly the same amounts of "if" statements
as with no case statements... 

and at the end... when you have everything written in C.. goto 
assembler, write the most assential code in assembler, 
DJGPP assembler can be a pain, but it's pretty good once you 
get use to it.

hope i've helped.

quark(particle)
quark AT webspan DOT net
http://www.webspan.net/~quark
C/C++/ASM/Java/JavaScript/HTML/Perl
 jon wrote in article <33775c59 DOT 19219875 AT news DOT cis DOT yale DOT edu>...
>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.
>
> 


- Raw text -


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