Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measuring performance using Android instrumentation test

My goal was to write automatic performance test for Android CPU intensive code using an instrumental test (AndroidJUnitRunner).

I was very surprised to find that the test results are not reliable, to simulate CPU intensive code, I want to test, I wrote the following loop

for(int i=0;i<1000000;i++){
    Math.pow(2,i);
}

The code was tested as an instrumental test and within an Android app

The result I got was as follows:

Instrumental test showed ~230ms to complete the loop whereas the same code on the same device (G5) took ~600ms

I will appreciate any clue why the execution of same code on AndroidJUnitRunner takes three times less time than on the real device while both of them finally are executed on the same device

like image 419
Denis Voloshin Avatar asked Jul 06 '17 18:07

Denis Voloshin


People also ask

What is instrumental test in Android?

Instrumented tests are tests that run on physical devices and emulators, and they can take advantage of the Android framework APIs and supporting APIs, such as AndroidX Test.

How do you evaluate Android app performance?

In Android Studio, launch the profiler by selecting View > Tool Windows > Profiler. button in the profiler to see the dropdown menu. Select your device, then select the application's entry under Other profileable processes. The profiler should attach to the application.

What is instrumentation in mobile testing?

Instrumentation is a process to prepare the application for testing or automation. Part of the instrumentation process may add "instruments" that allow the testing framework to gain access to parts of the application. Perfecto provides tools for instrumenting mobile applications for different purposes.

What is instrumental testing?

In summary, an instrumentation test provides a special test execution environment as launched via the am instrument command, where the targeted application process is restarted and initialized with basic application context, and an instrumentation thread is started inside the application process VM.


1 Answers

Simply speed comes from CPU, while you are executing some code, if CPU is not doing any heavy work and all CPU cores are up, it will execute your code pretty fast. In android, 'UI rendering' is most intensive work that AndroidJUnitRunner is not doing, that's why it is fast.

If you want to understand how android perform in different scenarios, take a look at this: https://www.youtube.com/playlist?list=PLWz5rJ2EKKc9CBxr3BVjPTPoDPLdPIFCE

like image 140
Manish Kumar Avatar answered Nov 15 '22 06:11

Manish Kumar