Answers.Body: <p><a href="https://www.chessprogramming.org/Perft_Results" rel="nofollow noreferrer">Perft</a> speed can be affected by:</p>
  <ul>
  <li>Coding language - for example, compiled vs interpreted.</li>
  <li>Bulk counting - whether you un-make leaf nodes - I believe SF doesn't do this, which makes it significantly faster.</li>
  <li>How your move generator works - for example, whether it performs legality checks on the generated moves.</li>
  <li>Whether you're using CPU or GPU for move generation.</li>
  <li>CPU speed/frequency.</li>
  <li>CPU multi-processing - for example, whether your perft is single-threaded or multi-threaded.</li>
  <li>CPU cache size.</li>
  <li>Which position you're using for perft.</li>
  </ul>
  <p>Without knowing these variables, it's hard to say whether your perft numbers are reasonable or not.</p>
  <p>As an example, my single-threaded C# magic bitboard code does perft from the standard starting position at around 100 million nodes per second on a single core of a Ryzen 5950X processor.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-12T20:09:38.243Z
Answers.LastActivityDate: 2023-09-12T23:56:07.433Z
Answers.LastEditDate: 2023-09-12T23:56:07.433Z
Answers.UserDisplayName: HTTP 410
Answers.Body: <p>There are a number of reasons.
  The Main one is its aggressive <strong>Alpha Beta pruning</strong> and <strong>late move reductions</strong>.</p>
  <p>To explain a bit further.
  <strong>AB Pruning</strong> is a search algorithm which basically cuts out the number of nodes in its search tree. How it works is it stops evaluating when it determines and proves the move to be worse than another examined moves.</p>
  <p><strong>Late move reduction</strong> is a slightly harder concept but it again searches the &quot;tree&quot; more efficiently. It does this by effectively diving down a &quot;algorithmically&quot; more probably tree.</p>
  <p>If I remember the release paper correctly the elo for Stockfish 14 is 3350 +/-5% and that was based off a 4 threaded CPU.</p>
  <p>In short there are the implementation of mathematically proven formulae to do with pruning infinite possibilities to the most correct, whilst also searching deeper down the most probably correct line.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-12T19:13:59.113Z
Answers.Text: This seems to be an answer for a different question. The question was, how Stockfish achieves such a fast move generator and consequently perft speed, *not* how it reaches such a big depth.
Answers.UserDisplayName: koedem
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-15T07:02:04.273Z
Answers.Text: Programmatically you could return all legal moves in a fraction of a second and wouldn't need an engine at all. You need to stop and think about the function of a engine. Its role IS to determine the BEST result as FAST as possible. This is done by AB Pruning , late move reduction. Both are critical for how Stockfish returns accurate results so fast...not just its "depth"
Answers.UserDisplayName: Dheebs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-15T07:40:34.693Z
Answers.Text: That is not what the question asks though. The question does not ask how Stockfish is so strong, it asks for how its move generator is so fast. How its search or evaluation works is completely irrelevant for that question. The question even gives exact numbers of perft speeds to specify that the question really is only about the move generator and the make_move function, there's no ambiguity there.
Answers.UserDisplayName: koedem
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-25T12:34:20.273Z
Answers.LastActivityDate: 2021-08-25T12:34:20.273Z
Answers.UserDisplayName: Dheebs
Answers.Body: <p>5.5 million moves per seconds is very decent I would say. Enough to make a 2700 or 2800 rating engine with a good evaluation function. I made a bot without any bitboard and got to around 2.5-3.5 knps and managed to beat 2300-2400 bots on chess.com with a mediocre evaluation function. 130 million positions per second is 100% for multi threading bots. No way you can achieve that with only one core. I knew an a version of minmax with multithreading but I don't really suggest implementing it since it quite hard to get it right.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-12T19:16:54.173Z
Answers.Text: I agree that 5.5 MN/s is a decent search speed, however, the question was about perft specifically, which only measures the speed of your move generator (and first and foremost its correctness) without any evaluation or other search "overhead". For that 130 million moves generated per second does sound possible on one core.
Answers.UserDisplayName: koedem
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-12T18:50:44.367Z
Answers.LastActivityDate: 2023-09-12T18:50:44.367Z
Answers.UserDisplayName: Soucup Bogdan
Body: <p>I'm currently developing a bitboard-based chess engine for fun and can generate around 5.5 million positions per second on perft tests. I ran the same tests on Stockfish, which can do around 130 million positions per second. What is it that makes Stockfish (and other engines) so much faster?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-05-28T18:37:02.347Z
Comments.Text: Might be interesting for you: Parallel processing for Stockfish https://link.springer.com/chapter/10.1007/978-3-319-93713-7_40
Comments.UserDisplayName: Hauke Reddmann
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-05-29T08:10:16.187Z
Comments.Text: Other than following @adrasthea advice of posting this question in talkchess, you should try to improve it. In which language have you written your engine? What's your level of expertise at this language? Are you sure its move generator is bug free? Are you testing both engines under the same conditions? (it doesn't make sense to compare no parallelized and parallelized engines) Can you show your code?
Comments.UserDisplayName: emdio
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-05-29T21:51:34.160Z
Comments.Text: Classical bitboard implementations involving linear scanning are a far cry from Magic bitboards. It's a looong rabbit hole. Have you read for example https://rhysre.net/fast-chess-move-generation-with-magic-bitboards.html?
Comments.UserDisplayName: BaseZen
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-09-12T19:18:31.603Z
Comments.Text: Do you use bulk counting? I.e. do you make and unmake the "leaf" moves? I would guess Stockfish does not in perft, which makes it a lot faster than one might otherwise expect. (so for the last ply of perft it is enough to count the number of generated moves, you don't necessarily need to make and unmake each one)
Comments.UserDisplayName: koedem
Tags: <engines><stockfish><computer-chess>
Title: How is Stockfish so fast?
ThreadText: # How is Stockfish so fast?
  
  (Asked by: username_0 on 2021-05-28)
  
  I'm currently developing a bitboard-based chess engine for fun and can generate around 5.5 million positions per second on perft tests. I ran the same tests on Stockfish, which can do around 130 million positions per second. What is it that makes Stockfish (and other engines) so much faster?
  
  **Tags:** engines, stockfish, computer-chess
  
  > **Comments:**
  > **username_1**: Might be interesting for you: Parallel processing for Stockfish https://link.springer.com/chapter/10.1007/978-3-319-93713-7_40  
  > **username_2**: Other than following @adrasthea advice of posting this question in talkchess, you should try to improve it. In which language have you written your engine? What's your level of expertise at this language? Are you sure its move generator is bug free? Are you testing both engines under the same conditions? (it doesn't make sense to compare no parallelized and parallelized engines) Can you show your code?  
  > **username_3**: Classical bitboard implementations involving linear scanning are a far cry from Magic bitboards. It's a looong rabbit hole. Have you read for example https://rhysre.net/fast-chess-move-generation-with-magic-bitboards.html?  
  > **username_4**: Do you use bulk counting? I.e. do you make and unmake the "leaf" moves? I would guess Stockfish does not in perft, which makes it a lot faster than one might otherwise expect. (so for the last ply of perft it is enough to count the number of generated moves, you don't necessarily need to make and unmake each one)  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_5 on 2023-09-12. Score: 1
  
  [Perft](https://www.chessprogramming.org/Perft_Results) speed can be affected by:
  
  * Coding language - for example, compiled vs interpreted.
  * Bulk counting - whether you un-make leaf nodes - I believe SF doesn't do this, which makes it significantly faster.
  * How your move generator works - for example, whether it performs legality checks on the generated moves.
  * Whether you're using CPU or GPU for move generation.
  * CPU speed/frequency.
  * CPU multi-processing - for example, whether your perft is single-threaded or multi-threaded.
  * CPU cache size.
  * Which position you're using for perft.
  
  Without knowing these variables, it's hard to say whether your perft numbers are reasonable or not.
  
  As an example, my single-threaded C# magic bitboard code does perft from the standard starting position at around 100 million nodes per second on a single core of a Ryzen 5950X processor.
  
  
  ---
  
  ### Answer by username_6 on 2021-08-25. Score: 1
  
  There are a number of reasons.
  The Main one is its aggressive **Alpha Beta pruning** and **late move reductions**.
  
  To explain a bit further.
  **AB Pruning** is a search algorithm which basically cuts out the number of nodes in its search tree. How it works is it stops evaluating when it determines and proves the move to be worse than another examined moves.
  
  **Late move reduction** is a slightly harder concept but it again searches the "tree" more efficiently. It does this by effectively diving down a "algorithmically" more probably tree.
  
  If I remember the release paper correctly the elo for Stockfish 14 is 3350 +/-5% and that was based off a 4 threaded CPU.
  
  In short there are the implementation of mathematically proven formulae to do with pruning infinite possibilities to the most correct, whilst also searching deeper down the most probably correct line.
  
  > **Comments:**
  > **username_4**: This seems to be an answer for a different question. The question was, how Stockfish achieves such a fast move generator and consequently perft speed, *not* how it reaches such a big depth.  
  > **username_6**: Programmatically you could return all legal moves in a fraction of a second and wouldn't need an engine at all. You need to stop and think about the function of a engine. Its role IS to determine the BEST result as FAST as possible. This is done by AB Pruning , late move reduction. Both are critical for how Stockfish returns accurate results so fast...not just its "depth"  
  > **username_4**: That is not what the question asks though. The question does not ask how Stockfish is so strong, it asks for how its move generator is so fast. How its search or evaluation works is completely irrelevant for that question. The question even gives exact numbers of perft speeds to specify that the question really is only about the move generator and the make_move function, there's no ambiguity there.  
  
  ---
  
  ### Answer by username_7 on 2023-09-12. Score: 0
  
  5.5 million moves per seconds is very decent I would say. Enough to make a 2700 or 2800 rating engine with a good evaluation function. I made a bot without any bitboard and got to around 2.5-3.5 knps and managed to beat 2300-2400 bots on chess.com with a mediocre evaluation function. 130 million positions per second is 100% for multi threading bots. No way you can achieve that with only one core. I knew an a version of minmax with multithreading but I don't really suggest implementing it since it quite hard to get it right.
  
  > **Comments:**
  > **username_4**: I agree that 5.5 MN/s is a decent search speed, however, the question was about perft specifically, which only measures the speed of your move generator (and first and foremost its correctness) without any evaluation or other search "overhead". For that 130 million moves generated per second does sound possible on one core.  
  
  ---
  
  