Skip to content

Instantly share code, notes, and snippets.

Created July 20, 2017 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8d396dd847d207ce7ac3c1a5e05fe218 to your computer and use it in GitHub Desktop.
Save anonymous/8d396dd847d207ce7ac3c1a5e05fe218 to your computer and use it in GitHub Desktop.
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