Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Optimizing C code for speed

Author: Daniel Clausen

Date: 09:02:26 01/01/03

Go up one level in this thread



On January 01, 2003 at 11:50:58, Lieven Clarisse wrote:

>I was wondering if there is a good book about how to write efficient C code. I
>am not talking about algorithms, but the way *how* to write things, eg
>
>which is faster :
>do {}  while()    or     while () {}

Some points:

-these statements not necessarily do the same things (the do/while-version is
executed at least once, the while-only-version not necessarily)

-I wish people would worry less about speed and worry more about design. There
are things which are more readable with the 1st version, others with the 2nd
version. Why not use the more intuive version?

-Since the main work will most likely be done inside the loop, the speed gain is
most likely very small anyway, if any

-Which one is faster probably also depends on the context, so a general answer
is not possible

-that's just my opinion :)


>I know for instance that:
>
>ptr=&R[i];
>if((*ptr==3)||(*ptr==7)) {;}
>
>is faster then:
>
>if((R[i]==3)||(R[i]==7)) {;}

Apart from the fact, that the statements itself don't seem to do anything
useful, I don't see why a good compiler shouldn't be able to optimize the 2nd
version too. (as long as R is not declared volatile)

Sargon



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.