Author: David Blackman
Date: 21:11:06 04/17/00
Go up one level in this thread
On April 17, 2000 at 09:59:05, Georg v. Zimmermann wrote:
>Hi,
>
>I have no clue about some speed issues. I do not know how good most compilers
>are. For example
>
>1.)
>
>if (A == B) { result = 1; } else { result = 0; }
>
>and
>
>result = 0;
>if (A == B) { result = 1; }
>
>
>does accomplish exactly the same. But in the first way the program has to set
>result = X only once, while in the second way it has to set result = X twice
>sometimes. Do compiler detect this ? Or is there a speed difference ?
The second one is normally faster because it has one less branch, and branches
are slower than assignments. A good compiler might spot what is going on and
convert the first form to the second. I wouldn't worry about it.
>2.)
>
>I use integer values as flags, and use 1 = true and 0 = false. Would I get a
>speedup if I'd use a special boolean type ?
Don't worry about it. If you have thousands (literally) of flags it could be
worth declaring them as char to save some memory. Otherwise leave them.
>3.)
>
>Do lots of global variables slow a program down ? Is access to private variables
>faster ?
Might or might not. It depends what you are doing to them. Locals probably have
a better chance of getting into registers, which would be faster. Locals are in
most cases easier to understand, which can be nice if you are modifying the
code, or debugging.
>===
>
>Another thing: how much faster is the Microsoft C++ Compiler compared to the
>Cygnus Compiler ? Does it make a difference ?
It's probably a bit faster. I've heard 20% mentioned. That will make no
noticeable difference to the strength of a chess program. Don't worry about it.
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.