MicrobenchmarkScope
public 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 methods |
|
---|---|
final void |
Pause measurement until the next call to |
final void |
Resume measurement after a call to |
final @NonNull T |
<T extends Object> runWithMeasurementDisabled(@NonNull Function0<@NonNull T> block) Disable measurement for a block of code. |
Public methods
pauseMeasurement
public final void pauseMeasurement()
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
public final void resumeMeasurement()
Resume measurement after a call to pauseMeasurement
Kotlin callers should generally instead use runWithMeasurementDisabled
.
runWithMeasurementDisabled
public final @NonNull T <T extends Object> runWithMeasurementDisabled(@NonNull Function0<@NonNull T> block)
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) }