BenchmarkState


public final class BenchmarkState


Control object for microbenchmarking in Java.

Query a state object with androidx.benchmark.junit4.BenchmarkRule.getState, and use it to measure a block of Java with BenchmarkStateLegacy.keepRunning:

@Rule
public
BenchmarkRule benchmarkRule = new BenchmarkRule();

@Test
public
void sampleMethod() {
BenchmarkState state = benchmarkRule.getState();

int[] src = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
while (state.keepRunning()) {
int[] dest = new int[src.length];
System.arraycopy(src, 0, dest, 0, src.length);
}
}

Note that BenchmarkState does not give access to Perfetto traces.

Summary

Public methods

final boolean
final void
final void

Public methods

keepRunning

Added in 1.0.0
public final boolean keepRunning()

pauseTiming

Added in 1.0.0
public final void pauseTiming()

resumeTiming

Added in 1.0.0
public final void resumeTiming()