From: Marco Costalba Date: Fri, 21 Jun 2013 07:10:03 +0000 (+0200) Subject: Micro-optimize perft X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=e215a88cddd16e09;hp=e95e69515a8e30bcdcef84bd37656c3ea3099cd5 Micro-optimize perft Avoid to call perft function when we just need to count moves, at leaf nodes. Speed up of almost 2% No functional change. --- diff --git a/src/search.cpp b/src/search.cpp index de6c2542..f4f411c5 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -155,21 +155,17 @@ void Search::init() { size_t Search::perft(Position& pos, Depth depth) { - // At the last ply just return the number of legal moves (leaf nodes) - if (depth == ONE_PLY) - return MoveList(pos).size(); - StateInfo st; size_t cnt = 0; CheckInfo ci(pos); + const bool leaf = depth == 2 * ONE_PLY; for (MoveList it(pos); *it; ++it) { pos.do_move(*it, st, ci, pos.move_gives_check(*it, ci)); - cnt += perft(pos, depth - ONE_PLY); + cnt += leaf ? MoveList(pos).size() : perft(pos, depth - ONE_PLY); pos.undo_move(*it); } - return cnt; }