Skip to content

Commit

Permalink
chess+search+evaluation: add benchmarks for searching, evaluation,
Browse files Browse the repository at this point in the history
making a move and generating moves
  • Loading branch information
e0ff committed Nov 23, 2023
1 parent 5948168 commit 032e52c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ clean:

coverage:
go test -cover ./internal/chess

benchmark:
go test ./... -bench=. -run NONE
19 changes: 19 additions & 0 deletions internal/chess/movegen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package chess

import "testing"

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

for i := 0; i < b.N; i++ {
position.GenerateMoves(LegalMoveGeneration)
}
}

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

for i := 0; i < b.N; i++ {
position.GenerateMoves(CaptureMoveGeneration)
}
}
11 changes: 11 additions & 0 deletions internal/chess/position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,14 @@ func TestIsStalemate(t *testing.T) {
isStalemateTest(t, StartingFen, White, false)
isStalemateTest(t, StartingFen, Black, false)
}

// Benchmarks

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

for i := 0; i < b.N; i++ {
position.MakeUciMove("d2d4")
position.Undo()
}
}
15 changes: 15 additions & 0 deletions internal/evaluation/evaluator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package evaluation

import (
"rosaline/internal/chess"
"testing"
)

func BenchmarkEvaluate(b *testing.B) {
position, _ := chess.NewPosition(chess.StartingFen)
evaluator := NewEvaluator()

for i := 0; i < b.N; i++ {
evaluator.Evaluate(position)
}
}
17 changes: 17 additions & 0 deletions internal/search/negamax_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package search

import (
"rosaline/internal/chess"
"rosaline/internal/evaluation"
"testing"
)

func BenchmarkNegamax(b *testing.B) {
position, _ := chess.NewPosition(chess.StartingFen)
evaluator := evaluation.NewEvaluator()
searcher := NewNegamaxSearcher(evaluator)

for i := 0; i < b.N; i++ {
searcher.Search(position, 4)
}
}

0 comments on commit 032e52c

Please sign in to comment.