Skip to content

Instantly share code, notes, and snippets.

@bastionkid
Last active September 6, 2022 08:56
Show Gist options
  • Save bastionkid/4ace15312c1c6cd76cb107a00a80e0cb to your computer and use it in GitHub Desktop.
Save bastionkid/4ace15312c1c6cd76cb107a00a80e0cb to your computer and use it in GitHub Desktop.
App startup timing test with and without Baseline Profiles
@RunWith(AndroidJUnit4::class)
class BaselineProfileBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun startupNoCompilation() {
startup(CompilationMode.None())
}
@Test
fun startupBaselineProfile() {
startup(CompilationMode.Partial(
baselineProfileMode = BaselineProfileMode.Require
))
}
private fun startup(compilationMode: CompilationMode) {
benchmarkRule.measureRepeated(
packageName = YOUR_APP_PACKAGE_NAME,
metrics = listOf(StartupTimingMetric()),
iterations = 10,
startupMode = StartupMode.COLD,
compilationMode = compilationMode
) { // this = MacrobenchmarkScope
pressHome()
startActivityAndWait()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment