Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: General efficiency question

Author: José Carlos

Date: 00:02:17 04/22/02

Go up one level in this thread


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

>Generally when I ask around (besides here) about chess programming questions I
>don't get very good answers, because I don't think most other programmers
>understand computer chess. Normally something like this wouldn't even matter,
>but because of the nature of chess programs repetitive nature in a handful of
>short functions it seems like a possibly more important issue.
>
>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. I'm not
>sure how costly dereferencing a pointer is or if it even costs anything, but if
>it costs even an extra instruction, and you do a dozen dereferences in your make
>move and unmake move functions, and quite a few in your evaluation function, and
>multiply how many dereferences you do by how many nodes you do in a normal
>search, that's a lot of wasted instructions.
>
>So is it faster to pass a pointer to a position structure around to all of your
>makemove, unmakemove, evaluation, etc. functions or to have some global
>variables that the program acts upon?
>
>If it is faster to use global data, is the speed difference trivial? For
>example, if you save a lot of instructions from using global data, but it only
>gets you another 1000 nodes in a 60 second search it's not a huge difference.
>
>What are some basic things that I do to write efficient code? Basic rules, such
>as pass a pointer instead of a copy of the entire structure. Things like that.
>
>And how could I test something like this in the future? For example, if I want
>to find out the cost of dereferencing a pointer. Where can I learn about these
>kinds of basic computer computational kinds of things? Any book or website
>recommendations? I'm a product of growing up with Microsoft so I was never
>really exposed to the more basic lower level computer issues like some of you
>guys who were writing chess programs in the 70's before I was born :)
>
>Thanks for any help and advice you can offer.
>
>Russell

  I'm not sure if I understand your question correctly, but I'll try to give my
2 cents:
  The information about the position on the board changes move after move. You
need to save it so that you get it back when you unmake the moves. You can
recalculate some data, but not all. For example, you need to store the moves.
Tipically, you'll use a stack.
  I've found saving faster than recalculating for almost everything, but you can
test it yourself by profiling. Create a set of different positions and write a
function that searches all of them to a certain depth or fixed time, and then
run it with the profiler. You can also not use the profiler, but count time and
nodes and repeat the test after making small changes, but make sure you repeat
the test with exact same conditions several times to get an average.
  Apart from the "saving data" issue, I rather have all my position information
together in memory for cache performance. So I prefer a big struct with all the
related data inside, rather than isolated global variables.

  José C.



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.