diff --git a/Makefile b/Makefile index 4d4580a..8b4d4c3 100644 --- a/Makefile +++ b/Makefile @@ -17,3 +17,6 @@ clean: coverage: go test -cover ./internal/chess + +benchmark: + go test ./... -bench=. -run NONE diff --git a/internal/chess/movegen_test.go b/internal/chess/movegen_test.go new file mode 100644 index 0000000..fd863b9 --- /dev/null +++ b/internal/chess/movegen_test.go @@ -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) + } +} diff --git a/internal/chess/position_test.go b/internal/chess/position_test.go index cdfe5bf..c479a85 100644 --- a/internal/chess/position_test.go +++ b/internal/chess/position_test.go @@ -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() + } +} diff --git a/internal/evaluation/evaluator_test.go b/internal/evaluation/evaluator_test.go new file mode 100644 index 0000000..6bd5104 --- /dev/null +++ b/internal/evaluation/evaluator_test.go @@ -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) + } +} diff --git a/internal/search/negamax_test.go b/internal/search/negamax_test.go new file mode 100644 index 0000000..3f6bae1 --- /dev/null +++ b/internal/search/negamax_test.go @@ -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) + } +}