Created
July 20, 2017 06:42
-
-
Save anonymous/8d396dd847d207ce7ac3c1a5e05fe218 to your computer and use it in GitHub Desktop.
the description for this gist
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
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