Created
December 18, 2017 10:41
-
-
Save hisui/e05ee6725df64097b7377000a9966983 to your computer and use it in GitHub Desktop.
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
def busyLoop(time: Int, threads: Int) = Action { implicit r => | |
val started = System.currentTimeMillis() | |
val workers = (0 until threads).map { _ => | |
val out = new Thread({ () => | |
val digest = MessageDigest.getInstance("SHA-256") | |
while (started + time * 1000 >= System.currentTimeMillis()) { | |
digest.update(UUID.randomUUID().toString.getBytes(StandardCharsets.US_ASCII)) | |
} | |
}) | |
out.start() | |
out | |
} | |
var count = 0 | |
while (workers.exists(_.isAlive)) { | |
count += 1 | |
} | |
Ok(Json.obj("count" -> count)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment