AndroidBenchmarkRunner

public class AndroidBenchmarkRunner


Instrumentation runner for benchmarks, used to increase stability of measurements and minimize interference.

To use this runner, put the following in your module level build.gradle:

android {
defaultConfig {
testInstrumentationRunner "androidx.benchmark.junit4.AndroidBenchmarkRunner"
}
}

Minimizing Interference

This runner launches a simple opaque activity used to reduce benchmark interference from other windows. Launching other activities is supported e.g. via ActivityTestRule and ActivityScenario - the opaque activity will be relaunched if not actively running before each test, and after each test's cleanup is complete.

For example, sources of potential interference:

  • live wallpaper rendering

  • homescreen widget updates

  • hotword detection

  • status bar repaints

  • running in background (some cores may be foreground-app only)

Clock Stability

While it is better for performance stability to lock clocks with the ./gradlew lockClocks task provided by the gradle plugin, this is not possible on most devices. The runner provides a fallback mode for preventing thermal throttling.

On devices that support android.view.Window.setSustainedPerformanceMode, the runner will set this mode on the window of every Activity launched (including the opaque Activity mentioned above). The runner will also launch a continuously spinning Thread. Together, these ensure that the app runs in the multithreaded stable performance mode, which locks the maximum clock frequency to prevent thermal throttling. This ensures stable clock levels across all benchmarks, even if a continuous suite of benchmarks runs for many minutes on end.

Summary

Public constructors

Public methods

@CallSuper void

Inherited methods

From class AndroidJUnitRunner
From class Instrumentation
@NonNull TestLooperManager
void
@NonNull Instrumentation.ActivityMonitor
addMonitor(
    @NonNull IntentFilter p0,
    @NonNull Instrumentation.ActivityResult p1,
    boolean p2
)
@NonNull Instrumentation.ActivityMonitor
addMonitor(
    @NonNull String p0,
    @NonNull Instrumentation.ActivityResult p1,
    boolean p2
)
void
void
void
void
void
void
void
void
void
void
void
boolean
void
@NonNull Bundle
@NonNull Bundle
@NonNull ComponentName
@NonNull Context
@NonNull String
@NonNull Context
@NonNull UiAutomation
@NonNull UiAutomation
boolean
invokeContextMenuAction(@NonNull Activity p0, int p1, int p2)
boolean
invokeMenuActionSync(@NonNull Activity p0, int p1, int p2)
boolean
@NonNull Application
newApplication(
    @NonNull ClassLoader p0,
    @NonNull String p1,
    @NonNull Context p2
)
void
void
void
void
void
void
sendStatus(int p0, @NonNull Bundle p1)
void
void
void
void
setInTouchMode(boolean p0)
void
@NonNull Activity
void

This method is deprecated. Deprecated in Java

void
void
void

This method is deprecated. Deprecated in Java

void
void
void
@NonNull Activity
@NonNull Activity
From class MonitoringInstrumentation
void
void
void
void
void
void
void
void
void
void
execStartActivities(
    @NonNull Context who,
    @NonNull IBinder contextThread,
    @NonNull IBinder token,
    @NonNull Activity target,
    @NonNull Array<@NonNull Intent> intents,
    @NonNull Bundle options
)
@NonNull Instrumentation.ActivityResult
execStartActivity(
    @NonNull Context who,
    @NonNull IBinder contextThread,
    @NonNull IBinder token,
    @NonNull Activity target,
    @NonNull Intent intent,
    int requestCode
)
@NonNull Instrumentation.ActivityResult
execStartActivity(
    @NonNull Context who,
    @NonNull IBinder contextThread,
    @NonNull IBinder token,
    @NonNull Activity target,
    @NonNull Intent intent,
    int requestCode,
    @NonNull Bundle options
)
@NonNull Instrumentation.ActivityResult
execStartActivity(
    @NonNull Context who,
    @NonNull IBinder contextThread,
    @NonNull IBinder token,
    @NonNull Fragment target,
    @NonNull Intent intent,
    int requestCode,
    @NonNull Bundle options
)
@NonNull Instrumentation.ActivityResult
execStartActivity(
    @NonNull Context who,
    @NonNull IBinder contextThread,
    @NonNull IBinder token,
    @NonNull String target,
    @NonNull Intent intent,
    int requestCode,
    @NonNull Bundle options
)
@NonNull Instrumentation.ActivityResult
execStartActivity(
    @NonNull Context who,
    @NonNull IBinder contextThread,
    @NonNull IBinder token,
    @NonNull