Created
August 15, 2020 12:28
-
-
Save Elvis10ten/3c08832173a8a4e6d23d689d47e165cb 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
object TimerResolution { | |
@JvmStatic | |
fun main(args: Array<String>) { | |
val numRepeat = 10 | |
var total = 0L | |
for(repeatIndex in 0 until numRepeat) { | |
val startTime = System.nanoTime() | |
var stopTime = System.nanoTime() | |
while(startTime == stopTime) { | |
stopTime = System.nanoTime() | |
} | |
total += (stopTime - startTime) | |
} | |
val mean = (total.toDouble() / 1E6) / numRepeat | |
val meanFormatted = String.format("%1.6f", mean) | |
println("nanoTime() resolution: ${meanFormatted}ms."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment