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:
- Quick sort
- Shell sort
- Array flip
- Method call
- Half division method
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
- | QS | SS | Swap | Div2 | Empty |
---|
JNI (sim) | 10590 | 253735 | 699 | 210339 | 13895 |
---|
JAVA (sim) | 100650 | 4573416 | 7861 | 334483 | 7745 |
---|
Sim% | 89.48 | 94.45 | 91.11 | 37,12 | -79,41 |
---|
*% - shows how much faster JNI from Java works
HTC Magic (32A 1.5, 2.6.29-myhero-bfs)
- | QS | SS | Swap | Div2 | Empty |
---|
Jni | 7469 | 117139 | 880 | 109197 | 8885 |
---|
Java | 63569 | 2902912 | 5959 | 213278 | 5193 |
---|
% | 88.25 | 95.96 | 85.23 | 48.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

And now let's compare it to an iPhone, it's not worth waiting for miracles ...
iphone
- | QS | SS | Swap | Div2 | Empty |
---|
HTC Magic JNI | 7469 | 117139 | 880 | 109197 | 8885 |
---|
iphone | 33531 | 1310358 | 1820 | 22405 | 769 |
---|
% | 77.73 | 91.06 | 51.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”.

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.