Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save maskaravivek/5234993011863ffb2b2c704f927626d8 to your computer and use it in GitHub Desktop.

Select an option

Save maskaravivek/5234993011863ffb2b2c704f927626d8 to your computer and use it in GitHub Desktop.
const val TARGET_PACKAGE = "com.circleci.samples.todoapp"
fun MacrobenchmarkRule.measureStartup(
profileCompiled: Boolean,
startupMode: StartupMode,
iterations: Int = 3,
setupIntent: Intent.() -> Unit = {}
) = measureRepeated(
packageName = TARGET_PACKAGE,
metrics = listOf(StartupTimingMetric()),
compilationMode = if (profileCompiled) {
CompilationMode.SpeedProfile(warmupIterations = 3)
} else {
CompilationMode.None
},
iterations = iterations,
startupMode = startupMode
) {
pressHome()
val intent = Intent()
intent.setPackage(TARGET_PACKAGE)
setupIntent(intent)
startActivityAndWait(intent)
}
@LargeTest
@RunWith(Parameterized::class)
class StartupBenchmarks(private val startupMode: StartupMode) {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun startupMultiple() = benchmarkRule.measureStartup(
profileCompiled = false,
startupMode = startupMode,
iterations = 5
) {
action = "com.circleci.samples.target.STARTUP_ACTIVITY"
}
companion object {
@Parameterized.Parameters(name = "mode={0}")
@JvmStatic
fun parameters(): List<Array<Any>> {
return listOf(StartupMode.COLD, StartupMode.WARM, StartupMode.HOT)
.map { arrayOf(it) }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment