From 53648921bcb6113d21f449af914d1e7a65d848fc Mon Sep 17 00:00:00 2001 From: mlykotom Date: Mon, 28 Nov 2022 11:16:37 +0100 Subject: [PATCH] Custom startup benchmark Change-Id: Ib402e5d818843cd305344be8283c7fa135291abe --- .../nowinandroid/startup/StartupBenchmark.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt index 5d83d89b2..99a4cb516 100644 --- a/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt +++ b/benchmarks/src/main/java/com/google/samples/apps/nowinandroid/startup/StartupBenchmark.kt @@ -90,3 +90,32 @@ abstract class AbstractStartupBenchmark(private val startupMode: StartupMode) { forYouWaitForContent() } } + +class StartupBenchmark { + @get:Rule + val benchmarkRule = MacrobenchmarkRule() + + @Test + fun startupNoCompilation() = startup(CompilationMode.None()) + + @Test + fun startupBaselineProfile() = startup(CompilationMode.Partial(baselineProfileMode = Require)) + + @Test + fun startupFullCompilation() = startup(CompilationMode.Full()) + + private fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated( + packageName = PACKAGE_NAME, + metrics = listOf(StartupTimingMetric()), + compilationMode = compilationMode, + iterations = 30, + startupMode = COLD, + setupBlock = { + pressHome() + } + ) { + startActivityAndWait() + // Waits until the content is ready to capture Time To Full Display + forYouWaitForContent() + } +}