edenman
06/11/2020, 4:03 AMTimeMark.elapsedSince(other: TimeMark)
? or plans to add it?jw
06/11/2020, 4:21 AMjw
06/11/2020, 4:23 AMjw
06/11/2020, 4:23 AMedenman
06/11/2020, 4:31 AM@Suppress("unused")
class DebugTimer(private val logger: (String) -> Unit) {
private var firstEvent = TimeSource.Monotonic.markNow()
private var lastEvent = firstEvent
private var isFirstEvent = true
fun log(message: String) {
val now = TimeSource.Monotonic.markNow()
val elapsedSinceLast = lastEvent.elapsedSince(now)
val elapsedSinceFirst = if (isFirstEvent) null else firstEvent.elapsedSince(now)
val totalSuffix = elapsedSinceFirst?.let { "(total ${elapsedSinceFirst})" } ?: ""
logger.invoke("DTimer: $message took $elapsedSinceLast $totalSuffix")
lastEvent = now
isFirstEvent = false
}
}
edenman
06/11/2020, 4:31 AMelapsedNow()
for both of those but then the values are slightly different between the two callsnkiesel
06/11/2020, 7:24 PMval tv1 = measureTimedValue { block1 }; val tv2 = measureTimedValues { block2 }
not do what you want?edenman
06/11/2020, 7:59 PMval timer = DebugTimer.start()
buildThing()
timer.log("building")
eatTacos()
timer.log("eating tacos")
makes it easier to see which parts of a method take the most timejw
06/11/2020, 8:08 PMlastEvent + elapsedSinceLast
to get a new TimeMark
for when you measuredjw
06/11/2020, 8:09 PMjw
06/11/2020, 8:11 PMjw
06/11/2020, 8:15 PMjw
06/11/2020, 8:22 PMjw
06/11/2020, 8:26 PMedenman
06/11/2020, 9:00 PMedenman
06/11/2020, 9:00 PMlastMark + elapsed
as the way to update the mark