Perft speed

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
marcelk
Posts: 348
Joined: Sat Feb 27, 2010 12:21 am

Re: Perft speed

Post by marcelk »

It seems a bit slowish indeed. I tried on the 2.0GHz Core2Duo.
My method is mailbox structure. Single-threaded, bulk counting, but including SEE for every generated move:

Code: Select all

Rookie> perft 5
5 4865609 (0.156 seconds)
Rookie> perft 6
6 119060324 (4.125 seconds)
Rookie> perft 7
7 3195901860 (105.479 seconds)
On the other hand, one shouldn't worry too much about perft speed until you do your 2nd engine rewrite or so.
ericlangedijk

Re: Perft speed

Post by ericlangedijk »

Well this is about the third rewrite... Focusing on GenMoves, MakeMove and UnMakeMove now.
I'm using Delphi XE and worrying a bit about the speed in general.
Int64 operations, array access.
And maybe access of my boardstructure, which has it's fields not aligned on 32 or 64 bit .
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Perft speed

Post by jwes »

ericlangedijk wrote:Thanks for the response.
There is still a lot of optimization to do.

I make pseudolegal moves and check after having made the move if we runned into a check. I work with Bitboards and incrementally update 4 occupationmasks (normal, rotated90, rotated45 and rotated315).
Is this the best way to handle that? Or is there a smarter way?
To my astonishment GenerateMoves() took much less time than I thought.

GenerateMoves - 7,94% of the time used
MakeMove - 19,94% of the time used
UnmakeMove - 16,68% of the time used
RunnedIntoCheck - 14,31% of the time used
Where the rest of the time is going I still have to figure out.

I use Perft (after it runs correct in a lot of testpositions) now to check the basic speed.
It was numbers like these that made me give up on rotated bitmaps.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Perft speed

Post by bob »

jwes wrote:
ericlangedijk wrote:Thanks for the response.
There is still a lot of optimization to do.

I make pseudolegal moves and check after having made the move if we runned into a check. I work with Bitboards and incrementally update 4 occupationmasks (normal, rotated90, rotated45 and rotated315).
Is this the best way to handle that? Or is there a smarter way?
To my astonishment GenerateMoves() took much less time than I thought.

GenerateMoves - 7,94% of the time used
MakeMove - 19,94% of the time used
UnmakeMove - 16,68% of the time used
RunnedIntoCheck - 14,31% of the time used
Where the rest of the time is going I still have to figure out.

I use Perft (after it runs correct in a lot of testpositions) now to check the basic speed.
It was numbers like these that made me give up on rotated bitmaps.
What else is any better? I use magic because of the single occupied_squares bitboard that makes it more flexible, but I saw no speed gain by getting rid of the rotated stuff at all. It is just now more efficient to ask "If I remove this pawn here, will a rook now attack square X?" Before I would have to update all 4 occupied_squares bitboards before I could answer that and it made the code messier. Move generation didn't change a bit, and is, in fact, slower with magic because of the operations being done. But then Make/Unmake gain some speed by doing less updates, which turned into a "break-even" thing with regard to speed...
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Perft speed

Post by tpetzke »

Rotated BB are much harder to implement (at least for me) than the magic ones but not slower in execution.

Magic BB helped me, because I have a legal move generator and the validation code that verifies the king is not in check after the move creates a new occupied board bitboard where the move was done and checks whether the own king is now attacked. This is simpler with magic bb but very specific to my implementation.

Thomas...
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: Perft speed

Post by Don »

bob wrote:
Dann Corbit wrote:Some engines hash perft counting, so keep that in mind when you do comparisons.
Correct. Here are a couple of examples from Crafty, starting position. Core-2 duo laptop (2.53ghz):

model name : Intel(R) Core(TM)2 Duo CPU P9600 @ 2.53GHz

perft 5: total moves=4865609 time=0.22

perft 6: total moves=119060324 time=5.36


No hashing or other tricks inside Crafty... it was never intended to be a speed test, but was a "correctness test" instead...
The perft in komodo does not hash but it's still a very useful optimization since it allows you do correctness tests faster, or deeper, or both.
ericlangedijk

Re: Perft speed

Post by ericlangedijk »

I know NPS is not everything but some basic speed would be nice.
Perft(6) takes 14 seconds here. 3 times as slow as Crafty's...
Well I'm working on it :)
User avatar
Kempelen
Posts: 620
Joined: Fri Feb 08, 2008 10:44 am
Location: Madrid - Spain

Re: Perft speed

Post by Kempelen »

bob wrote:
Dann Corbit wrote:Some engines hash perft counting, so keep that in mind when you do comparisons.
Correct. Here are a couple of examples from Crafty, starting position. Core-2 duo laptop (2.53ghz):

model name : Intel(R) Core(TM)2 Duo CPU P9600 @ 2.53GHz

perft 5: total moves=4865609 time=0.22

perft 6: total moves=119060324 time=5.36


No hashing or other tricks inside Crafty... it was never intended to be a speed test, but was a "correctness test" instead...
Bob, do you a checklegal() into makemove() or into the search()?
Fermin Serrano
Author of 'Rodin' engine
http://sites.google.com/site/clonfsp/
ericlangedijk

Re: Perft speed

Post by ericlangedijk »

As far as I could see Bob (Crafty) generates captures first. Then if a king is taken there the result is discarded.
User avatar
Kempelen
Posts: 620
Joined: Fri Feb 08, 2008 10:44 am
Location: Madrid - Spain

Re: Perft speed

Post by Kempelen »

ericlangedijk wrote:As far as I could see Bob (Crafty) generates captures first. Then if a king is taken there the result is discarded.
dont understand this. do you mean you generate all opponent captures when is your turn? that sounds strange to me. what it is usual is you generate the moves of who is in turn and the check if there is any ilegal with a is_attaked(k_sq) function, or allow the search to capture the king and return mate as score.....

also I am curious if crafty makemove (for perf) also compute the new hash.....
Fermin Serrano
Author of 'Rodin' engine
http://sites.google.com/site/clonfsp/