Skip to content

Instantly share code, notes, and snippets.

/post.scala
Created Jul 20, 2017

Embed
What would you like to do?
the description for this gist
class CachePingPongBenchmark {
var terminationLatch: CountDownLatch = null
var chessPlayers: Seq[ChessPlayer] = null
@Param(Array("sharedRooks", "separateRooks"))
var mode: String = ""
final val numMovesPerPlayer = 50000
final val numTotalOperations = numMovesPerPlayer * 2
final val executorService = Executors.newFixedThreadPool(2)
@Setup(Level.Invocation)
def setup(): Unit = {
terminationLatch = new CountDownLatch(2)
val rook1 = new Rook()
val rook2 = new Rook()
def sharedRooks: Stream[Rook] = Stream(rook1, rook2) append sharedRooks
def player(rooks: Stream[Rook]) =
new ChessPlayer(numMovesPerPlayer,sharedRooks,terminationLatch)
chessPlayers = mode match {
case "sharedRooks" =>
Seq(player(sharedRooks),player(sharedRooks))
case "separateRooks" =>
Seq(player(Stream.continually(rook1)),player(Stream.continually(rook2)))
}
}
@TearDown(Level.Trial)
def tearDown(): Unit = {
executorService.shutdownNow()
}
@Benchmark
@OperationsPerInvocation(numTotalOperations)
def benchmark = {
chessPlayers.foreach(executorService.execute)
terminationLatch.await(1, TimeUnit.MINUTES)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.