Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: General efficiency question

Author: Gareth McCaughan

Date: 15:10:20 04/22/02

Go up one level in this thread


On April 21, 2002 at 21:22:53, Russell Reagan wrote:

> My specific question is about whether it's faster to use a struct
> for your position, or to simply have some global variables.
> Global variables seem like they would be faster because you
> don't have to dereference the pointer.

1. All the people who have said that this is too small a difference
   to worry about, are absolutely right.

2. Global variables might be faster because you might save a
   pointer dereference. On the other hand, it'll be in cache
   all the time and shouldn't cost much. And if the pointer is
   in a register then you might have the same number of memory
   references either way. And global variables might be slower
   because constructing the address to look up might take a few
   instructions. All of these are small issues.

3. Global variables will make your program harder to parallelize.
   Don't worry about this. There are so many *real* difficulties
   with making a decent parallel program (the search, the hash
   tables, etc) that this sort of superficial thing will be lost
   in the noise.

4. When you have any optimization issue, there are three rules
   about optimizing code.

   a. "Jackson's First Rule": Don't do it.
   b. "Jackson's Second Rule" (for experts only): Don't do it yet.
   c. Profile your code. Measure, don't guess.

--
g



This page took 0.01 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.