Skip to content

Commit

Permalink
chess: add more benchmark cases for generating legal moves
Browse files Browse the repository at this point in the history
  • Loading branch information
e0ff committed Nov 26, 2023
1 parent 7bc475e commit 10c7adf
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions internal/chess/movegen_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
package chess

import "testing"

func BenchmarkGenerateLegalMoves(b *testing.B) {
position, _ := NewPosition(StartingFen)
import (
"fmt"
"testing"
)

func generateLegalMovesBenchmark(b *testing.B, fen string) {
position, _ := NewPosition(fen)
for i := 0; i < b.N; i++ {
position.GenerateMoves(LegalMoveGeneration)
}
}

func BenchmarkGenerateLegalMoves(b *testing.B) {
cases := []struct {
Name string
Fen string
}{
{
Name: "StartingPosition",
Fen: StartingFen,
},
{
Name: "LargestNumberOfLegalMoves",
Fen: "R6R/3Q4/1Q4Q1/4Q3/2Q4Q/Q4Q2/pp1Q4/kBNNK1B1 w - - 0 1",
},
{
Name: "InCheck",
Fen: "rn2kbnr/ppp2ppp/3pb3/4p3/2B1q3/BPN5/P1PP1PPP/R2QK1NR w KQkq - 0 6",
},
}

for _, c := range cases {
b.Run(fmt.Sprintf("%s", c.Name), func(b *testing.B) {
generateLegalMovesBenchmark(b, c.Fen)
})
}
}

func BenchmarkGenerateCaptureMoves(b *testing.B) {
position, _ := NewPosition(StartingFen)

Expand Down

0 comments on commit 10c7adf

Please sign in to comment.