BenchmarkRule.Scope


public final inner class BenchmarkRule.Scope


Handle used for controlling timing during measureRepeated.

Summary

Public methods

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

Disable timing for a block of code.

Public methods

runWithTimingDisabled

Added in 1.0.0
public final @NonNull T <T extends Object> runWithTimingDisabled(@NonNull Function0<@NonNull T> block)

Disable timing for a block of code.

Used for disabling timing 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)

  • Disabling timing during per-loop verification

@Test
fun bitmapProcessing() = benchmarkRule.measureRepeated {
val input: Bitmap = runWithTimingDisabled { constructTestBitmap() }
processBitmap(input)
}