📜 ⬆️ ⬇️

Android NDK vs SDK vs iPhone

Environment


We will write on MacOS, as the karmic koala is still “awakening”.
Eclipse Galileo, Android SDK 1.6r1 & NDK 1.6r1, installed and configured.
We will write on NDK 1.5, because only HTC Magic (32A) is available on hand.
This testing is written in order to "test" the ground before porting the game from iPhone to Android.

Testing


The following options were taken as tests:

Why such a choice?
"Half-division method", for the equation Y = 3 * cos (2 * x-4) in the interval (-10; 10) with an accuracy of 10 ^ (- 15), was chosen
since there is no coprocessor in the device to speed up floating-point calculations, it was therefore interesting to see whether the transition from Java to JNI would result in a performance gain. Another thing is large amounts of data and a large number of calls to "methods". To check the recursion in the compartment with a large amount of data, quick sorting was taken, to eliminate recursion, Shell algorithm was used. To test the performance of working specifically with data, use an array flip.
To estimate the cost of calling a JNI and Java "method", we call the dummy method 10,000 times.
For sorting, we use an int array of 10,000 elements, preformed.
The results were obtained for the simulator (2.4GHz Intel Core 2 Duo), HTC Magic (32A, 1.5, kernel 2.6.29 + bfs), as well as for iPhone3G (3.1). All test methods were written in pure C.

results


Simulator


-QSSSSwapDiv2Empty
JNI (sim)1059025373569921033913895
JAVA (sim)100650457341678613344837745
Sim%89.4894.4591.1137,12-79,41

*% - shows how much faster JNI from Java works

HTC Magic (32A 1.5, 2.6.29-myhero-bfs)


-QSSSSwapDiv2Empty
Jni74691171398801091978885
Java63569290291259592132785193
%88.2595.9685.2348.8-71,1

*% - shows how much faster JNI from Java works
')
Time for the Android platform was shot using the java.lang.System.nanoTime () function, for the iPhone using mach_absolute_time ().
Each test was run 30 times, the result was averaged. The first result was skipped, since it was knocked out of the general indicator, apparently related to the specifics of Java.
As can be seen from the results, NDK is very effective when working with large amounts of data, a large increase is also observed when transferring “mathematics” to JNI, the only negative is the “price” of the call.
Simulator

HTC Magic
HTC Magic
And now let's compare it to an iPhone, it's not worth waiting for miracles ...

iphone


-QSSSSwapDiv2Empty
HTC Magic JNI74691171398801091978885
iphone335311310358182022405769
%77.7391.0651.65-387.38-1055,4

*% - shows how much faster iPhone Magic works

The half-division method is not represented in the diagram, since it is known that the iPhone with its coprocessor of floating-point acceleration of mathematics will simply crush Magic, which we can see from the results. Dummy methods are also removed, since the iPhone compiler optimizes well “such code”.
iPhone
The results just hit me. Losing only in mathematics and code optimization. I think with the release of new devices will solve the first problem.

Sources of tests for the iPhone and Android .
PS as soon as it is possible to put firmware 1.6 on the phone, I will compare OpenGL.

Source: https://habr.com/ru/post/72883/


All Articles