MicrobenchmarkScope


public class MicrobenchmarkScope

Known direct subclasses
BenchmarkRule.Scope

Handle used for controlling measurement during measureRepeated.


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

Resume measurement after a call to pauseMeasurement.

final void

Resume measurement after a call to pauseMeasurement

final @NonNull T
<T extends Object> runWithMeasurementDisabled(@NonNull Function0<@NonNull T> block)

Disable measurement for a block of code.

Public methods

pauseMeasurement

Added in 1.4.0-alpha08
public final void pauseMeasurement()

Resume measurement after a call to pauseMeasurement.

Kotlin callers should generally instead use runWithMeasurementDisabled.

resumeMeasurement

Added in 1.4.0-alpha08
public final void resumeMeasurement()

Resume measurement after a call to pauseMeasurement

Kotlin callers should generally instead use runWithMeasurementDisabled.

runWithMeasurementDisabled

Added in 1.4.0-alpha08
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)
    }