measureNanoTime
Executes the given block and returns elapsed time in nanoseconds.
Since Kotlin
1.0Samples
import kotlin.system.*
fun main() {
//sampleStart
var sqrt = 0
val number = 1000
val timeInNanos = measureNanoTime {
while (sqrt * sqrt < number) sqrt++
}
println("(The operation took $timeInNanos ns)")
println("The approximate square root of $number is between ${sqrt - 1} and $sqrt")
//sampleEnd
}