Author: Gian-Carlo Pascutto
Date: 09:50:22 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 ?
It's usually not worth bothering over such tiny details. Most half-decent
compilers can indeed do these kind of optimizations for you.
Instead, focus on clear, readable code. Use the structure which is
the easiest to read and understand.
>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 ?
Not at all. For the CPU, booleans and integers are the same anyway.
>3.)
>
>Do lots of global variables slow a program down ? Is access to private >variables faster ?
Maybe. Local, automatic variables are usually optimized to machine registers,
whereas the global variable will have to be copied to and from mem at least
once. (probably an oversimplification ?)
>Another thing: how much faster is the Microsoft C++ Compiler compared to the
>Cygnus Compiler ? Does it make a difference ?
Yes, most people, including me, find VC++ to be noticably faster.
(about 20% for me)
--
GCP
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.