mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-10-06 14:29:39 +00:00
24 lines
488 B
Kotlin
24 lines
488 B
Kotlin
package gay.pizza.pork.tool
|
|
|
|
import kotlin.system.measureNanoTime
|
|
|
|
fun maybeLoopAndMeasure(loop: Boolean, measure: Boolean, block: () -> Unit) {
|
|
fun withMaybeMeasurement() {
|
|
if (measure) {
|
|
val nanos = measureNanoTime(block)
|
|
val millis = nanos / 1000000.0
|
|
System.err.println("time taken: $millis ms (${nanos} ns)")
|
|
} else {
|
|
block()
|
|
}
|
|
}
|
|
|
|
if (loop) {
|
|
while (true) {
|
|
withMaybeMeasurement()
|
|
}
|
|
} else {
|
|
withMaybeMeasurement()
|
|
}
|
|
}
|