MicrobenchmarkScope
open class MicrobenchmarkScope
BenchmarkRule.Scope |
Handle used for controlling measurement during |
Scope handle for pausing/resuming microbenchmark measurement.
This is functionally an equivalent to BenchmarkRule.Scope which will work without the JUnit dependency.
Summary
Public functions |
|
|---|---|
Unit |
Pause measurement until the next call to |
Unit |
Resume measurement after a call to |
inline T |
<T : Any?> runWithMeasurementDisabled(block: () -> T)Disable measurement for a block of code. |
Public functions
pauseMeasurement
fun pauseMeasurement(): Unit
Pause measurement until the next call to resumeMeasurement.
resumeMeasurement must be called before exiting the measurement loop.
Re-entrant pausing is not supported.
Kotlin callers should generally instead use runWithMeasurementDisabled.
resumeMeasurement
fun resumeMeasurement(): Unit
Resume measurement after a call to pauseMeasurement
Kotlin callers should generally instead use runWithMeasurementDisabled.
runWithMeasurementDisabled
inline fun <T : Any?> runWithMeasurementDisabled(block: () -> T): T
Disable measurement for a block of code.
Used for disabling timing/measurement for work that isn't part of the benchmark:
-
When constructing per-loop randomized inputs for operations with caching,
-
Controlling which parts of multi-stage work are measured (e.g. View measure/layout)
-
Per-loop verification
import androidx.benchmark.junit4.measureRepeated @Test fun bitmapProcessing() = benchmarkRule.measureRepeated { val input: Bitmap = runWithMeasurementDisabled { constructTestBitmap() } processBitmap(input) }