28-11-2012, 04:18 PM
Evaluating Performance of Android Platform Using Native C for
Embedded Systems
Evaluating Performance of Android Platform Using Native.pdf (Size: 115.6 KB / Downloads: 72)
INTRODUCTION
Recently, the Android platform [1] supported by
Google is widely used in mobile devices. Due to its
openness, the use of Android platform has proliferated
in mobile devices as well as in other embedded systems.
The Android platform can be applied to embedded
systems such as robot control systems.
In most embedded systems, C and C++ languages are
commonly used as effective languages to control
devices. In contrast, in embedded systems operated via
the Android platform, developers should create
applications by using Java language provided by
Android SDK [2]. Generally, Android applications,
based on Java language, are slower than applications
written in native C/C++ languages when the program
needs to execute complex operations because Android
applications are executed on Dalvik Virtual Machine [3].
Such Android applications based on Java language
make it difficult to manage all kinds of devices by using
only Android frameworks.
Android NDK [4] was first released in June 2009. It
enables Android application developers to manage
devices in detail beyond the limit of the framework and
to reuse legacy code written in C/C++ language easily.
Android NDK can also improve the performance of the
Android application if Android application developers
use it appropriately.
ANDROID NDK AND JNI
Android NDK
Android NDK is a toolset that can embed
components using native libraries from C/C++ code in
Android applications. Android NDK enables Android
application developers to use native code for
performance-critical portions of their applications and to
reuse legacy code written in C/C++ language.
Android application developers need to consider the
advantages and disadvantages of using native code.
Using native code does not always enhance application
performance, but it always increases application
complexity. Android NDK is effective in CPI-intensive
operations, such as physics simulation, and signal
processing. It is effective in reusing a large mass of
legacy C/C++ code [4].
Android NDK Revision 4 was released in May 2010.
This version of the NDK provides a simplified build
system through the new ndk-build build command. It
adds support for easy native debugging of generated
machine code on production devices through the new
ndk-gdb command. In addition, there are some added
features that support Android 2.2[4].
Integer Calculation
This experiment shows the difference in terms of
integer calculation performance between an Android
application using the native code library from C source
and an Android application using the same algorithm
written in Java language only. We measured the
execution time of finding the prime number algorithm
that returns a prime number of the Nth time of the input
number. This algorithm uses only integer calculation
rather than a fast floating-point algorithm using square
root.
results. The x-axis of the graph represents input number
N. The y-axis of the graph represents execution time in
milliseconds. As we can see from the results, using the
native C library is faster than using the same algorithm
running on Dalvik virtual machine only. The larger the
size of the input number, the greater the performance
gap between the case of using native C library and the
case of not using it.
Heap Memory Allocation Algorithm
We measured the time of allocating heap memory
whose size is calculated by multiplying 4Kbyte by the
user input number.
Fig.7 shows the results of the heap memory allocation
algorithm experiment. The x-axis of the graph
represents the input number. The y-axis of the graph
represents the execution time in milliseconds. As we
can see from the results, using the native C library is
faster than using the same algorithm running on Dalvik
virtual machine only.
Generally, heap memory is used when we try to
create an object in Java language and to allocate
dynamic memory in C/C++ language. C/C++
developers use dynamic memory allocation to avoid
memory wastage by static memory allocation and
restrictions on a program behavior. However, dynamic
memory allocation is slower than static memory
allocation. Dynamic memory allocation also carries
risks such as memory leaks, and memory exhaustion [8].
Though allocating heap memory in native C/C++
libraries is much faster than using the same behavior
running on Dalvik virtual machine only, developers
need to avoid dynamic memory allocation in native
C/C++ frequently. They should carefully exploit
dynamic memory allocation.
CONCLUSION
In this paper, we showed the difference in terms of
performance between an Android application using the
native code library from C source and an Android
application using the same algorithm running on Dalvik
virtual machine only. We conducted an experiment in
five parts. First, we measured JNI communication
delays that occurred due to using the JNI. And we found
that these delays do not have influence on the
experimental results because of its slightness. In every
part of the experiment-integer calculation, floating-point
calculation, memory access algorithm, heap memory
allocation algorithm-, using native C library achieves
faster results than using the same algorithm running on
Dalvik virtual machine only.
It is worth noting that the memory access algorithm
test showed a considerable performance difference
depending on whether or not the native code library was
used.