效能測試
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
應用程式執行階段效能可分為本機測試和現場測試。請注意,這兩個區域提供的結果和指標皆不相同。只要結果本身是明確的,這種差異就屬於可接受的範圍。
實地測試
實地測試可協助您瞭解應用程式在實際環境下,與實際使用者的互動情形。這項指標非常重要,有助於瞭解應用程式在實地環境中的表現。您可以使用 Google Play Vitals 和 Firebase Performance Monitoring 等工具,取得使用者的現場指標。
您可以使用 AndroidX 追蹤記錄程式庫新增追蹤點,為欄位指標提供更多背景資訊和洞察資料。
您也可以使用 ApplicationStartInfo
和 ApplicationExitInfo
,進一步瞭解使用者啟動和退出應用程式的詳細資訊。
AndroidX JankStats 程式庫可匯總並記錄影格轉譯速度緩慢和影格遺失的情形,以利進一步分析。
本機測試
我們提供基準測試程式庫,方便您在本機測試應用程式的執行階段效能。它分為 macrobenchmark 程式庫,可用於測試整個使用者流程的效能,以及 microbenchmark 程式庫,可用於分析應用程式或程式庫的熱門迴圈效能。
所有效能測試都應在實體裝置上執行。這是確保評估效能的唯一方法,是確保裝置實際發生的效能。執行階段效能測試的結果會因執行的裝置和裝置的繁忙程度而異。
應用程式效能可能會下滑。為避免迴歸,請務必經常執行效能測試。在理想情況下,每次新增功能或將程式碼併入主要分支時,都會對應用程式進行基準測試。效能監控功能的最低門檻是針對候選版本進行基準測試,並確認啟動時間和影格時間不會因為主要使用者旅程而降低。建議您盡可能執行基準測試,例如在將功能合併至主要分支或進行每晚版本建構前。
使用結果
效能測試是一個持續進行的過程。建議您以可隨時間比較的方式儲存效能測試結果。
你可以透過多種方式利用效能測試結果。
- 改善成效:根據評估結果,優先改善成效
- 避免迴歸:確保新版本不會發生效能迴歸問題
- 正式版監控:瞭解是否有開發期間未發現的問題
如要進一步瞭解 Android 執行階段效能測試,請參閱應用程式效能指南。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Performance tests\n\nApp runtime performance can be divided into local testing and field testing.\nKeep in mind that both of these areas provide different results and\nmetrics. As long as the results are in itself conclusive, that divergence is\nacceptable.\n\nField testing\n-------------\n\nField testing helps you to understand how an app performs with real users under\nreal world conditions. It is an important area and helps to understand how an\napp performs in the field. You can use tools such as [Google Play Vitals](/topic/performance/vitals) and\n[Firebase Performance Monitoring](https://firebase.google.com/docs/perf-mon) to get field metrics from\nusers.\n\nYou can use the [AndroidX Tracing](/jetpack/androidx/releases/tracing) library to add trace points which\nprovides more context and insights to field metrics.\n\nYou can also use [`ApplicationStartInfo`](/reference/android/app/ApplicationStartInfo) and [`ApplicationExitInfo`](/reference/android/app/ApplicationExitInfo) to\nget more detailed information on application start and exit from users.\n\nThe [AndroidX JankStats](/topic/performance/jankstats) library enables aggregating and reporting of slow\nand dropped frames for further analysis.\n\nLocal testing\n-------------\n\nTo locally test the runtime performance of an app we provide the benchmarking\nlibrary. It is divided into the [macrobenchmark](/topic/performance/benchmarking/macrobenchmark-overview) library, which can be used\nto test the performance of entire user flows and the [microbenchmark](/topic/performance/benchmarking/microbenchmark-overview)\nlibrary, which is used to analyze hot loop performance of an application or\nlibrary.\n\nAll performance tests should run on a physical device. This is the only way to\nensure that the performance you're measuring is the actual performance\noccurring on a device. Runtime performance tests will produce different results\ndepending on the device they run on and how busy the device is.\n\nApplication performance can regress. To avoid regressions it's important to run\nperformance tests frequently. In an ideal scenario an app is benchmarked every\ntime a new feature is added or code is merged into the main branch. The bare\nminimum of performance monitoring is to benchmark release candidates and verify\nthat startup time and frame timing does not regress for major user journeys.\nWe recommend you run benchmarks whenever possible, such as before merging a\nfeature to the main branch or for nightly builds.\n\nUse the results\n---------------\n\nPerformance testing is an ongoing process. We recommend that you store results\nof performance tests in a way that they can be compared over time.\n\nYou can use results of performance tests in several ways.\n\n- Performance improvement - Use measurement results to prioritize performance improvement\n- Regression avoidance - Ensure there are no performance regressions with new releases\n- Production monitoring - Understand whether there are issues you're not seeing during development\n\nTo learn more about Android runtime performance testing, see the\n[guide to app performance](/performance)."]]