Timing.kt
TLDR
The Timing.kt
file in the leakcanary.internal
package contains a single method measureDurationMillis
that is used to measure the elapsed time in milliseconds for executing a given block of code.
Methods
measureDurationMillis
This method measures the elapsed time in milliseconds for executing a given block of code. It takes a lambda expression block
as a parameter, which represents the code to be executed. The method uses the SystemClock.uptimeMillis()
method to get the current system time before and after executing the block. It subtracts the start time from the end time to calculate the elapsed time in milliseconds and returns the result.
Note: This method is internal
and is only accessible within the leakcanary.internal
package. It is declared as inline
to improve performance by avoiding the creation of additional objects.
package leakcanary.internal
import android.os.SystemClock
/**
* Executes the given [block] and returns elapsed time in milliseconds using [SystemClock.uptimeMillis]
*/
internal inline fun measureDurationMillis(block: () -> Unit): Long {
val start = SystemClock.uptimeMillis()
block()
return SystemClock.uptimeMillis() - start
}