Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Optimizing C code for speed

Author: Bruce Moreland

Date: 16:02:03 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 () {}
>
>-------
>I know for instance that:
>
>ptr=&R[i];
>if((*ptr==3)||(*ptr==7)) {;}
>
>is faster then:
>
>if((R[i]==3)||(R[i]==7)) {;}

How do you know this?

It is true or not true, depending upon the local context.  If you are using "R"
and "i" together, the compiler can figure out what you are doing sometimes.  If
this is one of those times, then doing weird pointer stuff is just confusing to
everyone -- possibly including the compiler.

Also, why do you care if your code goes fast?  This seems like a stupid
question, but often, it is the *best* question, and the answer is, "I don't".

And even if you find something that needs to go fast, the fact that you ask the
question, and need to know the real answer, means that you need to go to the
root, which is in this case the generated assembly and profiler output.

bruce



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.