Java vs C app performance – Gary explains

preview_player
Показать описание


Java is the official language of Android, but you can also write apps in C or C++ using the NDK. But which language is faster on Android?

----------------------------------------------------
Stay connected to Android Authority:

Follow the Team:
Рекомендации по теме
Комментарии
Автор

You should benchmark traversing an array of structs. In C and C++, you can access data directly, but in Java, you cannot. Expect a 10 times slow down in Java due to cache misses.

milasudril
Автор

in Gary's comparison between C and Java, he was only comparing between the relative performance between the two.
However, he did not compare the relative size of programs in memory.

The foot print.
And C has a much much smaller footprint than Java.
And for some embedded systems memory footprint is a big factor,
not just performance.
That is why some embedded developers are sticking with C rather that migrating
to Java.

RightToSelfDefense
Автор

Is it fair to estimate performance only by running time? I think memory usage should have been shown as well.

kassymakhmetbek
Автор

Java is the reason why your phone needs umpteen bajillion cores just to be responsive.

mrflamewars
Автор

The problem with these results is that all of them are very focused on just performing lots of math. In a real application, while these may make up a good amount of the code, you also have to deal with lots of allocations/freeing memory or processing strings, arrays, and other data structures that isn't reflected by raw math performance. With AOT (ahead-of-time) compilation (rather than JIT/just-in-time), ART can reduce a lot of the runtime bottlenecks (runtime type information can be removed, functions can be inlined, generic code can be specialized) in a way that still matches the device quite well. But the problem is that ART wouldn't be able to get rid of all your allocations or delay garbage collection to parts of the program where not much performance is needed on its own, and that's where C/C++ would help out a ton.

FalconGames
Автор

This channel needs more "Gary explains" videos!

SLS-
Автор

The optimization point can't be overstated. A skilled C programmer should be able to squeeze out a lot more performance because of the granular control over low level functions.

However there's a lot more room to screw things up, too.

wtfpwnzred
Автор

Yeah C is "slightly" faster than Java :D

mmr-xhcy
Автор

Was the C code compiled with -O0, -O1, -O2, or -O3?

derstreber
Автор

One has to be very careful with these micro-benchmarks. One thing to remember is that once the C compiler has run, the generated code is frozen for good. Dalvik and Art however, are adaptive in that they will look for "hot code paths" at runtime and try to optimize. For brute data processing, the C compiler will almost always come in first place - but Java can easily and automatically inline code across linkage boundaries (think libraries/components). In other words, to do Java justice here, one should compare a large C application vs. a large Java application (Visual Studio vs. IntelliJ comes to mind). Last but not least, you can not write an Android app using only C/C++ and the NDK; to interact with the operating-system you need Java!

CasperBang
Автор

Could someone help me out here, how would this work for C? Since all you can submit to the play store is an apk do you need to package your c source code in the apk? Wouldn't this be easily RE'ed? Or do you use some sort of IL/bytecode for C in your apk that gets compiled at install time?

gijsleemrijse
Автор

I just like to say:

People who believe in Java being faster than C are about the same people who believe in moto-perpetual machines.

j/k, but you got the point ;-)

linf
Автор

Great video explanation of the speed difference between the two languages. Please make more like this!

serpentvert
Автор

which compiler have you used compiling your c-files? :) have you at least used a newer cpp compiler? :)

robby
Автор

hi, i also want to do work on NDK for my research for my masters degree... but every time i check the results java threads are faster than the native threads... i work on api level 23 and android marshmallow... any advise...?

ShahzadKhan
Автор

Anytime dealing with C as a student I think one word...pointers.

andrewmorse
Автор

Please tell me this guy doesn't have a watch on each hand.

typedef_
Автор

What about the executable size? I know this a 3-year-old video, but I would like to know the sizes of each if you still have the executables available to you.

neonz
Автор

Hey Gary brilliant video but I've got a question, I've heard you say multiple times in various videos that you've made an app for this and that, have you ever thought about making an app and publishing it on the playstore also did you have any input on making the AA app???...

xceeder
Автор

You also may want to extend your benchmark to not only include calculation. For example, most UI based software systems create lists, sort lists, search lists (and hash maps), data transformation, like form validation, translation from one representation into another, and serialization and deserialization. BTW: nice video.

reinerjung