Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: compiler troubles?

Author: Ricardo Gibert

Date: 09:37:21 03/28/00

Go up one level in this thread


On March 28, 2000 at 04:12:49, Colin Frayn wrote:

>On March 27, 2000 at 23:02:35, Paul Byrne wrote:
>
>>I just ran into an interesting problem.  I've been cleaning up my code lately
>>and just discovered that my MoveList class still has asserts in it.  MoveList
>>is basically just an array of moves and a counter for now, and adding a Move
>>is done by
>>    void Add(Move mv) { assert(num<MAX); moves[num++]=mv; }
>>It has now played over 8000 games, so my choice of MAX seems to be pretty
>>safe, and I removed the assert.
>
>I always leave all mine in the code just in case.  You never know when you might
>want to alter something later on and then you'll wonder why your program keeps
>crashing spuriously.
>

You can disable assert() using the macro NDEBUG.


>>The resulting program is more than 10% SLOWER, which was rather unexpected.
>>The only place Add is used is the move generator, so the move generator must
>>be running much slower to hurt the entire program that much.
>
>>Anyone have any idea what is happening here?
>
>If you put an assert in, often the compiler is able to optimise the code knowing
>certain conditions on the input parameters to each function, loop etc....
>

That would be surprising, but does rather make sense. Can you give a simple
example of this? I'd like to test this out. It would be great if I could use
assert() to optimize my code. It is certainly a good idea if this does work.
I've only thought of it as a debugging aid rather than a way of conveying
additional information to the compiler to optimise my code. Interesting.


>I've had a few wierd problems like that in that past.  I expect Dann knows a bit
>about this kind of thing.
>
>Cheers,
>Col
>
>Cheers,
>Col



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.