JarvisXerxes wrote:Chan Rasjid wrote:
Or are you ruuning your debug version with assert() turned on?
I discovered the terrible blunder right before Chan posted. You're absolutely right. I built my project in visual studio under "Debug mode" instead of "Release", which definitely slows things down by an order of magnitude.
But even a correct build gives me only 20000 kn/s, still way below the standard.
Thanks a lot to HGM for your detailed explanation. This clarifies a lot of mysteries. I'm glad to listen to advice directly from qperft's author.
I'd try out the proposed optimizations and restructure my movegen.
Hi Jim,
there are a couple of threads in the Programming subforum where problems like legality checking, perft speed etc. are discussed. The most recent one I remember is only few days or weeks old. I suggest that you check that one as well, in addition to all the valuable replies you already received here.
My summary for you:
1) Don't worry too much about speed at all. Writing bug-free code, implementing a decent tree search and setting up a powerful testing framework are much more important than speed when starting a new engine.
2) Don't worry too much about perft speed as well. Perft is mainly an important testing method to verify correctness of your move generator, make/unmake and basic data structures. Running perft faster saves some seconds or maybe minutes of testing time only.
3) Even doubling the speed of your move generator and make/unmake code would only have a very small impact on the playing strength of a real engine since usually an engine uses only a small portion of its search time for these parts while most of the time is used for static evaluation and search. For instance if your movegen/make/unmake initially takes 20% of all search time and you really manage to double its speed (not for perft, of course!) then previous 100% become 90% so you get an overall 10% speedup only. In reality numbers will be even much smaller.
4) Measuring search speed is usually done by counting the number of nodes visited, including leaves as well as internal nodes. A fair comparison of perft speed between different programs (on the same HW platform!) would require to compare these "nodes per second" numbers while "leaves per second" can be misleading since it depends heavily on the algorithm to calculate that number (see next point).
5) There is mainly one significant speedup trick for perft and that is "bulk counting" (already mentioned by HGM) where make/unmake is avoided as much as possible at the last ply above the horizon since you only need the number of legal moves. Just in case you have not done that already: the trick is that all pseudo-legal moves except
- check evasions,
- king moves,
- moves of pinned pieces, and
- ep captures
are always legal so these can be counted without make/unmake. So at least for perft you can calculate all squares of pinned pieces, save them in a bitboard, and use that together with the other conditions above to decide whether you need the legality test. This will usually result in a boost of perft speed. Whether this method also improves overall speed for the normal search depends on a couple of things, please refer to the recent thread I mentioned above for a discussion about this topic.
Sven