measureNanoTime

JVM
Native
1.0
inline fun measureNanoTime(block: () -> Unit): Long
For JVM

Executes the given block and returns elapsed time in nanoseconds.

import kotlin.system.*

fun main(args: Array<String>) {
//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
}
For Native

Executes the given block and returns elapsed time in nanoseconds.