delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/15/00:19:31

From: quacci AT vera DOT com (jon)
Newsgroups: comp.os.msdos.djgpp,rec.games.programmer
Subject: Re: Any tips on optimizing C code?
Date: Wed, 14 May 1997 03:37:15 GMT
Organization: Yale University
Lines: 41
Message-ID: <33793055.19327180@news.cis.yale.edu>
References: <33775c59 DOT 19219875 AT news DOT cis DOT yale DOT edu> <01bc5f6f$c3000be0$cf1afec3 AT robert> <337865D0 DOT FB8 AT cornell DOT edu>
NNTP-Posting-Host: slip-ppp-node-02.cs.yale.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Tue, 13 May 1997 09:00:00 -0400, "A. Sinan Unur" <asu1 AT cornell DOT edu>
wrote:

>Robert Blum wrote:
>> 
>> jon <quacci AT vera DOT com> 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.
>> 
>> Duh.. That must have been from a very old source of information. On 
>> the Pentium (I assume you use one), FP is even faster than integer 
>> performance.

I program on a 486 at home, and test all of it on a pentium at work.

If you mean straight multiplication and division, yes, the gap has
been closed, more or less. But a trick like bit-shifting is still
faster than regular division, integer or FP. And unfortunately, you
can only do such tricks with integers.

What I have found is that I've sped up my present project enormously
by making the key loops use integer math rather than FP- and while the
increase is greatest on my 486, it is still very significant on the
pentium too.

>actually, that has been so since the 486. michael abrash wrote about his
>experience in dr dobbs some time ago. anyway, the moreal of the story is
>"measure before you optimize".

Oh, I've measured and measured. This is why I posted this, and I'll
ask again- has somebody else done all the measuring already? Is there
someplace I can know that using a case is faster than an if, or are
static ints a plus in functions that are called a lot- stuff like
that. 

I've found out all sorts of weird things- like, looking up on lookup
table using a mutlidimensional array was *slower* than simply doing
the math each time in one case I was working on... that was
dissapointing. 

- Raw text -


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