BenchmarkState
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.