lichess-org / dartchess

Dart chess library for native platforms
https://pub.dev/packages/dartchess
GNU General Public License v3.0
35 stars 18 forks source link

Use Immutable collections and improve `Board` performance #10

Closed veloce closed 1 year ago

veloce commented 1 year ago

Benchmark with Board using standard mutable Map:

dart run benchmark
 DONE  ./benchmark/dartchess_benchmark.dart (129 s)
 ✓ make fen from initial position (50 us)
 ✓ make fen from random position (47 us)
 ✓ parse san moves (5 ms)
 ✓ parse san moves, play unchecked (5 ms)
 ✓ valid fen moves (64 us)
 ✓ algebraic legal moves (227 us)
 ✓ parsePgn - kasparov-deep-blue (2 ms)
 ✓ makePgn (307 us)
 ✓ perft (56 s)

Benchmark with Board using an IMap

dart run benchmark
 DONE  ./benchmark/dartchess_benchmark.dart (138 s)
 ✓ make fen from initial position (99 us)
 ✓ make fen from random position (61 us)
 ✓ parse san moves (5 ms)
 ✓ parse san moves, play unchecked (4 ms)
 ✓ valid fen moves (70 us)
 ✓ algebraic legal moves (266 us)
 ✓ parsePgn - kasparov-deep-blue (2 ms)
 ✓ makePgn (301 us)
 ✓ perft (59 s)

Benchmark with Board using only square sets (no Map):

dart run benchmark
 DONE  ./benchmark/dartchess_benchmark.dart (78 s)
 ✓ make fen from initial position (31 us)
 ✓ make fen from random position (24 us)
 ✓ parse san moves (1 ms)
 ✓ parse san moves, play unchecked (1 ms)
 ✓ valid fen moves (47 us)
 ✓ algebraic legal moves (238 us)
 ✓ parsePgn - kasparov-deep-blue (2 ms)
 ✓ makePgn (307 us)
 ✓ perft (29 s)