Instantly share code, notes, and snippets.

Embed
What would you like to do?
@ExperimentalContracts
fun main(args: Array<String>) {
var assign: String
val time = measureTimeMillis {
assign = "Value Assigned"
}
println("$time ms. spent assigning: '$assign'")
}
@ExperimentalContracts
private inline fun measureTimeMillis(block: () -> Unit): Long {
contract {
callsInPlace(block, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
}
val start = System.currentTimeMillis()
block()
return System.currentTimeMillis() - start
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment