4

Can android macro benchmark run without clear app's data?

because in my app it require user to accept the license, and the macrobenchmark clear app's data every time when it startup the application.

Chanson
  • 411
  • 4
  • 8
  • is this answer to your question? https://stackoverflow.com/questions/6134103/clear-applications-data-programmatically#answer-29197259 – Robin Hood Jun 08 '22 at 10:05
  • @RobinHood don't think that's relevant here considering OP is asking about the Macro benchmark specifically – a_local_nobody Jun 08 '22 at 10:19

1 Answers1

0

To bring your app to a specific state before starting to measure with macrobenchmark, use the setupBlock in the measureRepeated function:

benchmarkRule.measureRepeated(
        packageName = PACKAGE_NAME,
        metrics = listOf(StartupTimingMetric()),
        iterations = 5,
        startupMode = StartupMode.COLD,
        setupBlock = {
          acceptLicense() // <-- Use UIAutomator to perform user actions
        }
    ) {
        // Perform benchmark actions
    }
Ben Weiss
  • 17,182
  • 6
  • 67
  • 87
  • That's not helpful. My app loads something that's set up on the first run on non first runs. You just can not get the performance of typical run when the data is cleared. No amount UIAutomator can simulate a non-frist run. – johngray1965 May 02 '23 at 16:25