0

I have a project written in Java and I integrated it into an Android app (written in Java as well).
When I measured the execution time for the same method (which refers to several external libraries in the form of .jar files) on both PC and Android, I found that it runs faster on Android. The execution time was measured using the System.currentTimeMillis() method and The system configurations are as follows:

  • PC: Eclipse on a MacBook Air 2017 (Core i5+8GB RAM)
  • Android: native app on a Google Pixel 3XL (Snapdragon 845+4GB RAM)

It seems to me that the PC is superior in performance (although it is difficult to compare), so I find it strange that the execution time is shorter on Android.

However, after some research I also found that Java execution on Android is different from that on a PC: Java on Android runs on the Google Android Runtime (ART) and Java on PC runs on the Oracle JVM. Especially, the fact that Android adopts ahead-of-time (AOT) compilation seems to be advantageous to running methods that use .jar libraries on Android. In fact, taking a look at the breakdown of the execution time the time taken to execute codes that invoke jar libraries was much shorter than that on a PC.

So my question is, can such things happen? Can I simply attribute the result to the difference in runtimes and architectures and so on, or am I missing something to be taken into account? Can anyone shed a new light on this?

  • Try a Windows or Linux PC. Anyway this is nice to hear. So fast. – blackapps Jun 12 '20 at 08:04
  • Do you properly warm up the JVM and run the benchmark properly ? Using JMH will give you proper numbers – Marged Jun 12 '20 at 08:06
  • There's many possible reasons that this is the fact and it's really hard to tell if the measurement is accurate. First, [microbenchmarks are hard](https://stackoverflow.com/questions/504103/how-do-i-write-a-correct-micro-benchmark-in-java), especially for Java. Second, the Dalvik runtime and the JVM are very different beasts that are optimized very differently (with different goals and techniques). Third: it really, really depends on what your code is doing (is it doing heavy computation? Is some of the work offloaded to dedicated parts of the hardware?). – Joachim Sauer Jun 12 '20 at 08:27
  • @blackapps I've tried on a Windows PC with similar specifications (using Eclipse) but it was the same – manuru0117 Jun 12 '20 at 09:09
  • @Marged Thank you for the suggestion, I will look it up – manuru0117 Jun 12 '20 at 09:11
  • @JoachimSauer I'm new to benchmarking so probably I have to make some more research. My code is related to pairing-based cryptography and it performs computations like encryption and decryption. They are not that heavy, like ~1000ms on a PC. I'm not sure if they are offloaded to some hardware – manuru0117 Jun 12 '20 at 09:17
  • Number of cores in Android Snapdragon that you have mentioned are greater than Core i5 (8 vs 5). Although RAM is less in Android. If your app is cpu intensive and not memory intensive then your results are the expected ones. – muasif80 Jun 12 '20 at 09:26

0 Answers0