Skip to content

Instantly share code, notes, and snippets.

@Elvis10ten
Created August 15, 2020 12:28
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 Elvis10ten/3c08832173a8a4e6d23d689d47e165cb to your computer and use it in GitHub Desktop.
Save Elvis10ten/3c08832173a8a4e6d23d689d47e165cb to your computer and use it in GitHub Desktop.
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