Skip to content

Commit

Permalink
Merge pull request #620 from lenguyenthanh/improve-binary-fen-bench
Browse files Browse the repository at this point in the history
Improve BinaryFen benchmark
  • Loading branch information
lenguyenthanh authored Feb 6, 2025
2 parents 42725a2 + c22dde1 commit c101ed3
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions bench/src/main/scala/benchmarks/BinaryFenBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,43 @@ class BinaryFenBench:
)
)

@Benchmark
def read(bh: Blackhole) =
Blackhole.consumeCPU(Work)
bh.consume(binary.read)
import chess.variant.*
import chess.{ Mode as _, * }
import chess.format.FullFen
import chess.perft.Perft
import chess.format.Fen

@Param(Array("10", "100", "1000"))
var games: Int = scala.compiletime.uninitialized
var sits: List[Situation.AndFullMoveNumber] = scala.compiletime.uninitialized
var fens: List[BinaryFen] = scala.compiletime.uninitialized

@Setup
def setup(): Unit =
sits = makeSituations(Perft.randomPerfts, games)
fens = sits.map(BinaryFen.write)

private val situation = Situation.AndFullMoveNumber(Situation(Standard), FullMoveNumber(1))
private def makeSituations(perfts: List[Perft], games: Int): List[Situation.AndFullMoveNumber] =
perfts
.take(games)
.flatMap(x => Fen.read(Chess960, x.epd))
.map(Situation.AndFullMoveNumber(_, FullMoveNumber(1)))

@Benchmark
def write(bh: Blackhole) =
Blackhole.consumeCPU(Work)
bh.consume(BinaryFen.write(situation))
val games = this.sits
var i = 0
while i < games.size do
val game = games(i)
Blackhole.consumeCPU(Work)
bh.consume(BinaryFen.write(game))

@Benchmark
def read(bh: Blackhole) =
val games = this.fens
var i = 0
while i < games.size do
val fen = games(i)
Blackhole.consumeCPU(Work)
bh.consume(fen.read)
i += 1

0 comments on commit c101ed3

Please sign in to comment.