KT-27856 Add contracts to Timing.kt lambdas (#1987)

This commit is contained in:
Tsvetan
2020-01-21 13:42:21 +01:00
committed by ilya-g
parent 7dc29a1840
commit 5f0e3018db
@@ -6,10 +6,15 @@
@file:kotlin.jvm.JvmName("TimingKt")
package kotlin.system
import kotlin.contracts.*
/**
* Executes the given [block] and returns elapsed time in milliseconds.
*/
public inline fun measureTimeMillis(block: () -> Unit): Long {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
val start = System.currentTimeMillis()
block()
return System.currentTimeMillis() - start
@@ -19,6 +24,9 @@ public inline fun measureTimeMillis(block: () -> Unit): Long {
* Executes the given [block] and returns elapsed time in nanoseconds.
*/
public inline fun measureNanoTime(block: () -> Unit): Long {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
val start = System.nanoTime()
block()
return System.nanoTime() - start