measure
Thanks for your feedback!
Was this page helpful?
Executes the given block and returns elapsed time in nanoseconds.
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 }
xxxxxxxxxx
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")
Thanks for your feedback!