기준 프로필을 사용 설정한 경우 Jetpack Macrobenchmark를 사용하여 앱의 성능을 테스트한 후 그 결과를 기준 프로필을 사용하지 않은 벤치마크와 비교하는 것을 권장합니다. 이 접근 방식을 사용하면 앱 시작 시간(처음 표시하는 데 걸린 시간과 완전히 표시하는 데 걸린 시간 모두)이나 런타임 렌더링 성능을 측정하여, 생성된 프레임으로 인해 버벅거림이 발생할 수 있는지 확인할 수 있습니다.
Macrobenchmark를 사용하면 CompilationMode API를 통해 측정 전 컴파일을 제어할 수 있습니다. 다양한 CompilationMode 값을 사용하여 다양한 컴파일 상태의 성능을 비교합니다. 다음 코드 스니펫은 CompilationMode 매개변수를 사용하여 기준 프로필의 이점을 측정하는 방법을 보여줍니다.
@RunWith(AndroidJUnit4ClassRunner::class)classColdStartupBenchmark{@get:RulevalbenchmarkRule=MacrobenchmarkRule()// No ahead-of-time (AOT) compilation at all. Represents performance of a// fresh install on a user's device if you don't enable Baseline Profiles—// generally the worst case performance.@TestfunstartupNoCompilation()=startup(CompilationMode.None())// Partial pre-compilation with Baseline Profiles. Represents performance of// a fresh install on a user's device.@TestfunstartupPartialWithBaselineProfiles()=startup(CompilationMode.Partial(baselineProfileMode=BaselineProfileMode.Require))// Partial pre-compilation with some just-in-time (JIT) compilation.// Represents performance after some app usage.@TestfunstartupPartialCompilation()=startup(CompilationMode.Partial(baselineProfileMode=BaselineProfileMode.Disable,warmupIteration=3))// Full pre-compilation. Generally not representative of real user// experience, but can yield more stable performance metrics by removing// noise from JIT compilation within benchmark runs.@TestfunstartupFullCompilation()=startup(CompilationMode.Full())privatefunstartup(compilationMode:CompilationMode)=benchmarkRule.measureRepeated(packageName="com.example.macrobenchmark.target",metrics=listOf(StartupTimingMetric()),compilationMode=compilationMode,iterations=10,startupMode=StartupMode.COLD,setupBlock={pressHome()}){// Waits for the first rendered frame, which represents time to initial display.startActivityAndWait()// Waits for content to be visible, which represents time to fully drawn.device.wait(Until.hasObject(By.res("my-content")),5_000)}}
다음 스크린샷에서는 Google Pixel 7에서 실행된 Now in Android 샘플 앱의 결과를 Android 스튜디오에서 직접 확인할 수 있습니다. 결과에 따르면 컴파일하지 않은 것(324.8밀리초)과 대조적으로 기준 프로필을 사용할 때(229.0밀리초) 앱 시작이 가장 빠른 것을 확인할 수 있습니다.
그림 1. 최초 표시 시간을 보여주는 ColdStartupBenchmark 결과. 컴파일하지 않은 경우 324밀리초, 전체 컴파일한 경우 315밀리초, 부분 컴파일한 경우 312밀리초, 기준 프로필을 사용한 경우 229밀리초
이전 예에서는 앱이 첫 번째 프레임을 생성하는 데 걸린 시간인 처음 표시하는 데 걸린 시간(TTID)을 측정합니다. 그러나 여기에는 사용자가 앱과 상호작용을 시작할 수 있는 시간이 꼭 반영되는 것은 아닙니다. 완전히 표시하는 데 걸린 시간(TTFD) 측정항목은 완전히 사용할 수 있는 앱 상태를 유지하는 데 필요한 코드 경로를 측정하고 최적화하는 데 더 유용합니다.
TTID와 TTFD는 둘 다 중요하므로 모두 최적화하는 것이 좋습니다. TTID가 낮으면 사용자가 앱이 실제로 실행되고 있는지 직접 확인할 수 있습니다. 사용자가 앱과 빠르게 상호작용할 수 있도록 하려면 TTFD를 짧게 유지하는 것이 중요합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-27(UTC)"],[],[],null,["We recommend using [Jetpack Macrobenchmark](/topic/performance/benchmarking/macrobenchmark-overview) to test how an app performs when\nBaseline Profiles are enabled, and then compare those results to a benchmark\nwith Baseline Profiles disabled. With this approach, you can measure app startup\ntime---both time to initial and full display---or runtime rendering\nperformance to see if the frames produced can cause jank.\n\nMacrobenchmarks let you control pre-measurement compilation using the\n[`CompilationMode`](/reference/androidx/benchmark/macro/CompilationMode) API. Use different `CompilationMode` values to compare\nperformance with different compilation states. The following code snippet shows\nhow to use the `CompilationMode` parameter to measure the benefit of Baseline\nProfiles: \n\n```kotlin\n@RunWith(AndroidJUnit4ClassRunner::class)\nclass ColdStartupBenchmark {\n @get:Rule\n val benchmarkRule = MacrobenchmarkRule()\n\n // No ahead-of-time (AOT) compilation at all. Represents performance of a\n // fresh install on a user's device if you don't enable Baseline Profiles---\n // generally the worst case performance.\n @Test\n fun startupNoCompilation() = startup(CompilationMode.None())\n\n // Partial pre-compilation with Baseline Profiles. Represents performance of\n // a fresh install on a user's device.\n @Test\n fun startupPartialWithBaselineProfiles() =\n startup(CompilationMode.Partial(baselineProfileMode = BaselineProfileMode.Require))\n\n // Partial pre-compilation with some just-in-time (JIT) compilation.\n // Represents performance after some app usage.\n @Test\n fun startupPartialCompilation() = startup(\n CompilationMode.Partial(\n baselineProfileMode = BaselineProfileMode.Disable,\n warmupIteration = 3\n )\n )\n\n // Full pre-compilation. Generally not representative of real user\n // experience, but can yield more stable performance metrics by removing\n // noise from JIT compilation within benchmark runs.\n @Test\n fun startupFullCompilation() = startup(CompilationMode.Full())\n\n private fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated(\n packageName = \"com.example.macrobenchmark.target\",\n metrics = listOf(StartupTimingMetric()),\n compilationMode = compilationMode,\n iterations = 10,\n startupMode = StartupMode.COLD,\n setupBlock = {\n pressHome()\n }\n ) {\n // Waits for the first rendered frame, which represents time to initial display.\n startActivityAndWait()\n\n // Waits for content to be visible, which represents time to fully drawn.\n device.wait(Until.hasObject(By.res(\"my-content\")), 5_000)\n }\n}\n```\n| **Caution:** Run the benchmarks on a physical device to measure real world performance. Measuring performance on an Android emulator likely provides incorrect results, because resources are shared with its hosting machine.\n\nIn the following screenshot, you can see the results directly in Android Studio\nfor the [Now in Android sample](https://goo.gle/nia) app ran on Google Pixel 7. The\nresults show that app startup is fastest when using Baseline Profiles\n(**229.0ms** ) in contrast with no compilation (**324.8ms**).\n**Figure 1.** Results of `ColdStartupBenchmark` showing time to initial display for no compilation (324ms), full compilation (315ms), partial compilation (312ms), and Baseline Profiles (229ms). **Tip:** You can also retrieve the results as a JSON file to parse them as part of your CI pipeline. For more information, see [Benchmarking in CI](/topic/performance/benchmarking/benchmarking-in-ci).\n\nWhile the previous example shows app startup results captured with\n[`StartupTimingMetric`](/reference/androidx/benchmark/macro/StartupTimingMetric), there are other important metrics worth considering,\nsuch as [`FrameTimingMetric`](/reference/androidx/benchmark/macro/FrameTimingMetric). For more information about all the types of\nmetrics, see [Capture Macrobenchmark metrics](/topic/performance/benchmarking/macrobenchmark-metrics).\n\nTime to full display\n\nThe previous example measures the [time to initial display](/topic/performance/vitals/launch-time#time-initial) (TTID), which is\nthe time taken by the app to produce its first frame. However, this doesn't\nnecessarily reflect the time until the user can start interacting with your app.\nThe [time to full display](/topic/performance/vitals/launch-time#time-full) (TTFD) metric is more useful in measuring and\noptimizing the code paths necessary to have a fully useable app state.\n\nWe recommend optimizing for both TTID and TTFD, as both are important. A low\nTTID helps the user see that the app is actually launching. Keeping the TTFD\nshort is important to help ensure that the user can interact with the app\nquickly.\n\nFor strategies on reporting when the app UI is fully drawn, see [Improve\nstartup timing accuracy](/topic/performance/benchmarking/macrobenchmark-metrics#startup-accuracy).\n\nRecommended for you\n\n- Note: link text is displayed when JavaScript is off\n- \\[Write a Macrobenchmark\\]\\[11\\]\n- \\[Capture Macrobenchmark metrics\\]\\[12\\]\n- \\[App startup analysis and optimization {:#app-startup-analysis-optimization}\\]\\[13\\]"]]