I can't figure out how to use measureTime
in Kotlin Notebooks.
This code from docs:
import kotlin.time.measureTime
val timeTaken = measureTime {
Thread.sleep(100)
}
println(timeTaken)
Complains:
Line_40.jupyter.kts (1:17 - 28) This declaration needs opt-in. Its usage must be marked with '@kotlin.time.ExperimentalTime' or '@OptIn(kotlin.time.ExperimentalTime::class)'
I tried to add @ExperimentalTime
in front of the code, but it still shows the same error.
Is there a way to use measureTime
in Kotlin Notebooks?
Try this bro:
@ExperimentalTime
val timeTaken = measureTime {
Thread.sleep(100)
}
@JvmStatic
@ExperimentalTime
fun main(args: Array<String>) {
println(timeTaken)
}
OR :
companion object {
@OptIn(ExperimentalTime::class)
val timeTaken = measureTime {
Thread.sleep(100)
}
@JvmStatic
fun main(args: Array<String>) {
println(timeTaken)
}
}