Created
March 13, 2026 20:10
-
-
Save LethalMaus/32d4949de71f3a4a9bc2f31233e78014 to your computer and use it in GitHub Desktop.
Startup macrobenchmark snippet for Android app startup article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dev.jamescullimore.app.benchmark | |
| import androidx.benchmark.macro.CompilationMode | |
| import androidx.benchmark.macro.StartupMode | |
| import androidx.benchmark.macro.StartupTimingMetric | |
| import androidx.benchmark.macro.junit4.MacrobenchmarkRule | |
| import org.junit.Rule | |
| import org.junit.Test | |
| class StartupBenchmarks { | |
| @get:Rule | |
| val benchmarkRule = MacrobenchmarkRule() | |
| @Test | |
| fun coldStartupWithoutProfile_setupFlow() = measureColdStart( | |
| compilationMode = CompilationMode.None(), | |
| onboardingDone = false | |
| ) | |
| @Test | |
| fun coldStartupWithBaselineProfile_mainFlow() = measureColdStart( | |
| compilationMode = CompilationMode.Partial(), | |
| onboardingDone = true | |
| ) | |
| private fun measureColdStart( | |
| compilationMode: CompilationMode, | |
| onboardingDone: Boolean | |
| ) = benchmarkRule.measureRepeated( | |
| packageName = "dev.jamescullimore.app", | |
| metrics = listOf(StartupTimingMetric()), | |
| startupMode = StartupMode.COLD, | |
| compilationMode = compilationMode, | |
| iterations = 10 | |
| ) { | |
| launchForStartup(onboardingDone = onboardingDone) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment