-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Reduce number of games and nodes for PerftBench - Change val => var - Move unrelated calculation from benchmarks - Use more of Blackhole - @fork = 3 - Fix HashBench
- Loading branch information
1 parent
bb8ac13
commit 4077b54
Showing
5 changed files
with
162 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,39 @@ | ||
package benchmarks | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
import cats.syntax.all.* | ||
|
||
import java.util.concurrent.TimeUnit | ||
import chess.format.pgn.Fixtures | ||
import chess.format.pgn.Reader | ||
import chess.MoveOrDrop.move | ||
import chess.Hash | ||
import chess.format.pgn.{ Fixtures, Reader } | ||
import chess.MoveOrDrop.situationAfter | ||
import chess.{ Hash, Situation } | ||
|
||
@State(Scope.Thread) | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@Measurement(iterations = 15, timeUnit = TimeUnit.SECONDS, time = 3) | ||
@Warmup(iterations = 15, timeUnit = TimeUnit.SECONDS, time = 3) | ||
@Fork(value = 3) | ||
@Threads(value = 1) | ||
class HashBench: | ||
|
||
var games = Fixtures.gamesForPerfTest.traverse(Reader.full(_)).toOption.get.traverse(_.valid).toOption.get | ||
// the unit of CPU work per iteration | ||
private[this] val Work: Long = 10 | ||
|
||
var situations: List[Situation] = _ | ||
|
||
var situations = games.flatMap(_.moves).flatMap(_.move).map(_.situationAfter) | ||
@Setup | ||
def setup() = | ||
var results = for | ||
results <- Fixtures.gamesForPerfTest.traverse(Reader.full(_)) | ||
replays <- results.traverse(_.valid) | ||
yield replays.flatMap(_.moves).map(_.situationAfter) | ||
situations = results.toOption.get | ||
|
||
@Benchmark | ||
def hashes() = | ||
situations.map(Hash(_)) | ||
def hashes(bh: Blackhole) = | ||
var result = situations.map: x => | ||
Blackhole.consumeCPU(Work) | ||
Hash(x) | ||
bh.consume(result) |
9 changes: 3 additions & 6 deletions
9
bench/src/main/scala/benchmarks/InsufficientMaterialBench.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,35 @@ | ||
package benchmarks | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import org.openjdk.jmh.annotations.* | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
import cats.syntax.all.* | ||
|
||
import java.util.concurrent.TimeUnit | ||
import chess.format.pgn.Fixtures | ||
import chess.format.pgn.Parser | ||
import chess.format.pgn.{ Fixtures, Parser, PgnStr } | ||
|
||
@State(Scope.Thread) | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@Measurement(iterations = 15, timeUnit = TimeUnit.SECONDS, time = 3) | ||
@Warmup(iterations = 15, timeUnit = TimeUnit.SECONDS, time = 3) | ||
@Fork(value = 3) | ||
@Threads(value = 1) | ||
class ParserBench: | ||
|
||
var games = Fixtures.gamesForPerfTest | ||
// the unit of CPU work per iteration | ||
private[this] val Work: Long = 10 | ||
|
||
var games: List[PgnStr] = _ | ||
|
||
@Setup | ||
def setup() = | ||
games = Fixtures.gamesForPerfTest | ||
|
||
@Benchmark | ||
def pgnParser(): Boolean = | ||
games.traverse(Parser.full).isRight | ||
def pgnParser(bh: Blackhole) = | ||
var result = games.traverse { x => | ||
Blackhole.consumeCPU(Work) | ||
Parser.full(x) | ||
} | ||
bh.consume(result) | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,97 @@ | ||
package benchmarks | ||
|
||
import org.openjdk.jmh.annotations._ | ||
|
||
import chess.perft.Perft | ||
|
||
import org.openjdk.jmh.annotations.* | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
import chess.perft.{ Perft, Result } | ||
import chess.format.Fen | ||
import chess.variant.* | ||
|
||
@State(Scope.Thread) | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@Measurement(iterations = 15, timeUnit = TimeUnit.SECONDS, time = 3) | ||
@Warmup(iterations = 15, timeUnit = TimeUnit.SECONDS, time = 3) | ||
@Fork(value = 3) | ||
@Threads(value = 1) | ||
class PerftBench: | ||
|
||
var threecheckPerfts = Perft.threeCheckPerfts | ||
var nodeLimit = 10_000L | ||
var gameLimit = 100 | ||
// the unit of CPU work per iteration | ||
private[this] val Work: Long = 10 | ||
|
||
@Param(Array("50")) | ||
var games: Int = _ | ||
|
||
@Param(Array("10000")) | ||
var nodes: Long = _ | ||
|
||
var threecheckPerfts: List[Perft] = _ | ||
var antichessPerfts: List[Perft] = _ | ||
var atomicPerfts: List[Perft] = _ | ||
var crazyhousePerfts: List[Perft] = _ | ||
var racingkingsPerfts: List[Perft] = _ | ||
var hordePerfts: List[Perft] = _ | ||
var randomPerfts: List[Perft] = _ | ||
var trickyPerfts: List[Perft] = _ | ||
|
||
@Setup | ||
def setup(): Unit = | ||
threecheckPerfts = makePerft(Perft.threeCheckPerfts, games, nodes) | ||
antichessPerfts = makePerft(Perft.antichessPerfts, games, nodes) | ||
atomicPerfts = makePerft(Perft.atomicPerfts, games, nodes) | ||
crazyhousePerfts = makePerft(Perft.crazyhousePerfts, games, nodes) | ||
racingkingsPerfts = makePerft(Perft.racingkingsPerfts, games, nodes) | ||
hordePerfts = makePerft(Perft.hordePerfts, games, nodes) | ||
randomPerfts = makePerft(Perft.randomPerfts, games, nodes) | ||
trickyPerfts = makePerft(Perft.trickyPerfts, games, nodes) | ||
|
||
@Benchmark | ||
def threecheck() = | ||
bench(threecheckPerfts, ThreeCheck, nodeLimit, gameLimit) | ||
def threecheck(bh: Blackhole) = | ||
bench(threecheckPerfts, ThreeCheck)(bh) | ||
|
||
var antichessPerfts = Perft.antichessPerfts | ||
@Benchmark | ||
def antichess() = | ||
bench(antichessPerfts, Antichess, nodeLimit, gameLimit) | ||
def antichess(bh: Blackhole) = | ||
bench(antichessPerfts, Antichess)(bh) | ||
|
||
var atomicPerfts = Perft.atomicPerfts | ||
@Benchmark | ||
def atomic() = | ||
bench(atomicPerfts, Atomic, nodeLimit, gameLimit) | ||
def atomic(bh: Blackhole) = | ||
bench(atomicPerfts, Atomic)(bh) | ||
|
||
var crazyhousePerfts = Perft.crazyhousePerfts | ||
@Benchmark | ||
def crazyhouse() = | ||
bench(crazyhousePerfts, Crazyhouse, nodeLimit, gameLimit) | ||
def crazyhouse(bh: Blackhole) = | ||
bench(crazyhousePerfts, Crazyhouse)(bh) | ||
|
||
var hordePerfts = Perft.hordePerfts | ||
@Benchmark | ||
def horde() = | ||
bench(hordePerfts, Horde, nodeLimit, gameLimit) | ||
def horde(bh: Blackhole) = | ||
bench(hordePerfts, Horde)(bh) | ||
|
||
var racingkingsPerfts = Perft.racingkingsPerfts | ||
@Benchmark | ||
def racingkings() = | ||
bench(racingkingsPerfts, RacingKings, nodeLimit, gameLimit) | ||
def racingkings(bh: Blackhole) = | ||
bench(racingkingsPerfts, RacingKings)(bh) | ||
|
||
var randomPerfts = Perft.randomPerfts.take(50) | ||
@Benchmark | ||
def chess960() = | ||
bench(randomPerfts, Chess960, nodeLimit, gameLimit) | ||
def chess960(bh: Blackhole) = | ||
bench(randomPerfts, Chess960)(bh) | ||
|
||
var trickyPerfts = Perft.trickyPerfts | ||
@Benchmark | ||
def tricky() = | ||
bench(trickyPerfts, Chess960, nodeLimit, gameLimit) | ||
def tricky(bh: Blackhole) = | ||
bench(trickyPerfts, Chess960)(bh) | ||
|
||
private def makePerft(perfts: List[Perft], games: Int, nodes: Long) = | ||
perfts.take(games).map(_.withLimit(nodes)) | ||
|
||
private def bench(perfts: List[Perft], variant: Variant)(bh: Blackhole) = | ||
var x = perfts.map: | ||
Blackhole.consumeCPU(Work) | ||
_.calculate(variant) | ||
bh.consume(x) | ||
x | ||
|
||
private def bench(perfts: List[Perft], variant: Variant, nodeLimit: Long, gameLimit: Int) = | ||
perfts.take(gameLimit).map(_.withLimit(nodeLimit).calculate(variant)) | ||
extension (perft: Perft) | ||
def bench(variant: Variant): List[Result] = | ||
var situation = Fen.read(variant, perft.epd).get | ||
perft.cases.map: c => | ||
import Perft.* | ||
Blackhole.consumeCPU(Work) | ||
Result(c.depth, situation.perft(c.depth), c.result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters