# BenchmarkState

Artifact: [androidx.benchmark:benchmark-common](https://developer.android.com/jetpack/androidx/releases/benchmark) [View Source](https://cs.android.com/search?q=file:androidx/benchmark/BenchmarkState.kt+class:androidx.benchmark.BenchmarkState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.0.0)

*** ** * ** ***


```
class BenchmarkState
```

<br />

*** ** * ** ***

Control object for microbenchmarking in Java.

Query a state object with `https://developer.android.com/reference/kotlin/androidx/benchmark/junit4/BenchmarkRule#getState()`, and use it to measure a block of Java with `https://developer.android.com/reference/kotlin/androidx/benchmark/BenchmarkStateLegacy#keepRunning()`:

```kotlin
@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 functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/benchmark/BenchmarkState#keepRunning()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/benchmark/BenchmarkState#pauseTiming()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/benchmark/BenchmarkState#resumeTiming()()` |

## Public functions

### keepRunning

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.0.0)

```
fun keepRunning(): Boolean
```

### pauseTiming

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.0.0)

```
fun pauseTiming(): Unit
```

### resumeTiming

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.0.0)

```
fun resumeTiming(): Unit
```