Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: General efficiency question

Author: Roy Brunjes

Date: 19:14:31 04/21/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

Interesting question.  I would expect that generally it would cost more to
dereference the pointer (especially if it happens repeatedly as the program
searches for a move in a given position).  The real answer is likely "it
depends" and you may want to investigate compiler options that let you see the
machine instructions generated by the compiler.  Most compilers seem to offer
this kind of flag.  Then, you can see for yourself by counting machine cycles
per instruction generated to see which method is more efficient.  It could
depend upon the particulars of your environment (compiler, hardware,
compile-time flags, etc.) I suspect.





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.