BenchmarkRule.Scope


public final inner class BenchmarkRule.Scope extends MicrobenchmarkScope


Handle used for controlling measurement during measureRepeated.

Summary

Public methods

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

This method is deprecated. Renamed to runWithMeasurementDisabled to clarify all measurements are paused

Inherited methods

From androidx.benchmark.MicrobenchmarkScope
final void

Pause measurement until the next call to resumeMeasurement.

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

runWithTimingDisabled

Added in 1.0.0
Deprecated in 1.4.0-alpha09
public final @NonNull T <T extends Object> runWithTimingDisabled(@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)
    }