1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Return pairs for benchmark functions.

This commit is contained in:
Cedric Beust 2016-07-18 23:43:41 -08:00
parent db1207ac04
commit d37827ce93

View file

@ -1,12 +1,15 @@
package com.beust.kobalt.misc
fun benchmarkMillis(run: () -> Unit) : Long {
fun <T> benchmarkMillis(run: () -> T) : Pair<Long, T> {
val start = System.currentTimeMillis()
run()
return System.currentTimeMillis() - start
val result = run()
return Pair(System.currentTimeMillis() - start, result)
}
fun benchmarkSeconds(run: () -> Unit) = benchmarkMillis(run) / 1000
fun <T> benchmarkSeconds(run: () -> T) : Pair<Long, T> {
val result = benchmarkMillis(run)
return Pair(result.first / 1000, result.second)
}