简体   繁体   中英

Are programs written in Java for Android slower than equivalent written in C embedded into Objective-C for iOS?

In order to decide whether it is justified to start porting an existed iOS app (written in C) to Android, I have to estimate how fast will it be, if being implemented in Java. Some concern is the fact that Java code must be translated many times (to bytecode, then to a native one using JIT). It may affect a real time property (responsiveness) negatively , right?

What about the quality of generated code? Is it somehow comparable with gcc/llvm generated code? If yes, do you have a reference to the comparison results (paper)?

Good question. Several years ago the performance of the Sun (now Oracle) JVM would pale in comparison to native code. But things have changed .

Firstly, the VM running Android isn't your standard JVM. Its a beefed up VM rewritten by Google specifically for mobile use, where UI performance is given priority.

Secondly, a lot has happened over the past decade... a quote from this relevant article puts it nicely: Fifteen years ago, all we thought that Java needed to rule the known universe was a faster VM. We now have a much faster VM.

Finally, there's been a lot written about comparisons between iOS and Android in terms of performance. Here's a fifth link just for kicks. There's plently more out there. It comes down to several factors - what type of code you need to run, what your performance expectations are, and how much you're willing to invest to squeeze out the most bang for your buck. And if you think Dalvik is your bottleneck, you're capable of writing native C/C++ and use JNI in Android.

You can not compare the performance in this way. Your application will run on different pieces of hardware with different performance characteristics. The differences in performance between java/objective c is most probably negligible compared to the influence of the hardware. You should analyze the bottlenecks of your application and check if the targeted hardware can support it. If it's implemented in java does not matter that much.

As a test I once wrote a test app that executed a sorting algorithm on a large random list.

The C version ran about 10 times faster than the same Java version.

I would suspect that you will typically see Java running about 5 times slower than the equivalent C on the same platform.

The platform it's running on will also influence the speed of course.

Even though you shouldn't care about it, yes, the Java bytecode may be slightly slower. If you're totally worrying about performance then you could use the NDK, and write most of the app in C(++).

Decision whether to port to another platform usually comes from business side, not engineering. As for speed - it depends. Meanwhile JIT tends to be really fast, and it uses some optimisations at the runtime, which are not available to C compiled programs.

Nevertheless, it is impossible to predict what performance penaltiues or advantages could arise from porting without knowing what your program does.

And there is option to go with native C code which is accessed from android application - its perfromance would depend on hardware and be predictable.

Android Java isn't exactly interpreted as you think. In fact Java bytecode doesn't even make it to the device because the dalvik VM (android's JVM) doesn't interpret Java bytecode it runs DEX bytecode which is closer to the native processor format. So it's really hard to "guess" or extrapolate what the performance difference between Objective-C and Android at an arms length just based on knowing one is Java and one is native code. Not to mention you have their OS to compare as well: Linux variant vs. Mach kernel. Then Android doesn't map programs to processes in the same manner as iOS either. Given the differences in language, OS, system mapping, and variations in underlying SDK code you really can't decide without doing a little work on your side if you're going to have performance issues or not. But, that really shouldn't even matter because if there is a demand and need for your program on Android the market forces should be way more compelling than performance issues. You know the old saying "If it's really important to you, you'll find a way. If not you'll find an excuse."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM