0% found this document useful (0 votes)
2 views

Improving Performance android

This paper discusses programming techniques for improving performance in Android applications, focusing on the use of Java and Native C. It presents guidelines and experimental results comparing the performance of both languages across various algorithms, concluding that Native C generally offers better performance for integer, floating-point, and memory access operations, while Java is more efficient for string processing. The findings highlight the importance of efficient programming in mobile application development due to the constraints of mobile devices.

Uploaded by

kien9999kk123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Improving Performance android

This paper discusses programming techniques for improving performance in Android applications, focusing on the use of Java and Native C. It presents guidelines and experimental results comparing the performance of both languages across various algorithms, concluding that Native C generally offers better performance for integer, floating-point, and memory access operations, while Java is more efficient for string processing. The findings highlight the importance of efficient programming in mobile application development due to the constraints of mobile devices.

Uploaded by

kien9999kk123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Android Programming Techniques for

Improving Performance

Jae Kyu Lee Prof. Jong Yeol Lee


Dept. of Electronic Engineering Dept. of Electronic Engineering
Jeonbuk National University, JBNU Jeonbuk National University, JBNU
Jeonju, Republic of Korea Jeonju, Republic of Korea
e-mail: [email protected] e-mail: [email protected]

Abstract- Android has been researched in various mobile device The structure of the paper is as follows : Section II
fields such as Smartphone and Tablet PC. In here, we should introduces the architecture of Android, JNI and NDK. Section
remember that mobile devices have limited storage and III describes the implementation of the applications for
constrained battery life. Therefore, when developers develop performance measurement in detail. Section IV analyze the
applications, they should do efficient programming. In this measurement results. Section V gives the conclusion.
paper, we have proposed programming guidelines for an effective
way to improve performance in Android applications. We have
programmed Android applications using Java and Native C, and
II. BACKGROUND

compared the performance between the two languages. The


applications are composed of five categories such as JNI delay,
Integer, Floating-point, Memory access algorithm and String A. Android
processing. By analyzing the results, we propose a more efficient Android is a software stack for mobile devices that includes
way to program Android applications.
an operating system, middleware and key applications[3].
Keywords- Android; Android NDK; JNl; Performance
Google and other members of the Open Handset Alliance[4]
Evaluation; Native C collaborated on Android's development and release. The
Android architecture and its main components are shown in
"Fig. 1".
1. INTRODUCTION

Nowadays, Tablet PC and Smartphone are making a change


In our life. Since these mobile devices have become more
powerful and distributive, mobile computing has become more
important. As the market share of mobile operating systems
steadily grows and more IT applications are developed and
deployed on mobile devices[l]. Moreover, a
IDC(www.idc.org) survey suggests that 70% of organizations a
recurrently deploying at least one mobile application. These
trend is expected to continue[2].

Today, the most popular mobile operating systems are


Apple's iOS, Microsoft's Windows Mobile and Google's
Android. The Android provides the tools and APIs necessary to
begin developing applications on the Android platform using
the Java progr amming language. It gives developers an Figure 1. Architecture of Android.
opportunity to build applications for the Android developer
Challenge. So, many Android applications are being developed As shown in "Fig. 1", Android consists of a Linux
by developers around the world. Because mobile devices have Kemel(2.6) and some key applications (e.g. phone, browser,
limited storage and constrained battery life, the developers maps) running on a Java-based, object-oriented application
should pay more attention to the efficiency of the program framework on top of core libraries running on a Dalvik virtual
when they develop applications. machine featuring JIT(version 2.2 or later) compilation. Dalvik
virtual machine is one of the most prominent feature in
In this paper, we have implemented and analyzed Android
Android. Especially, It is optimized for slow CPU, relatively
applications to provide guidelines for an effective way to
little memory and to run on OS without any swap space. This is
improve the performance of Android applications.
also a register-based virtual machine. Therefore, the instruction A. Implementation of Applications to evaluate the
tends to be longer. The latest version of Android is the Android performance
2.3(also known as Android gingerbread release). In this paper, This section describes the design and implementation of
all experiments were run on the Android 2.3. applications for performance evaluation. The applications were
programmed by using JAVA and Native C. largely 2 kinds of
B. Android NDK & JNI ways. Java applications are developed based on commonly
The Android NDK is a toolset that lets you embed used Android development environment (SDK).
components that make use of native code in Android
Applications in Native C are developed by following
applications. Android applications run in the Dalvik virtual
procedure: First, write your application source code using Java
machine. The NDK allows you to implement parts of your
language (Activity, Service and so on). Then, create a header
applications using native-code languages such as C and
file containing Native C function prototype using 'javah ,
C++[5]. In addition, the NDK provides stable headers for libc
commands. Next, implement native method, which is an
(the C library), libm (the Math library), OpenGL ES (3D
implementation of the actual behavior. Finally, build the native
graphics library), the JNI interface, and other libraries. This can
library, and insert this library in the application package. The
provide benefits to certain classes of applications, in the form
behavior architecture of our Android applications using Native
of reuse of existing code and in some cases increased speed.
C is shown in "Fig. 3".
The Java Native Interface (JNI) is a powerful feature of the
Java platform. Applications that use the JNI can incorporate Android Application Package (.apk)
native code written in programming languages such as C and
C++, as well as code written in Java programming language. SoClab Benchmark Activity
So JNI enables one to write native methods to handle situations
when an application cannot be written entirely in the Java
programming language. Then the JNI allows programmers to
take advantage of the power of the Java Platform[6][7]. The
"Fig. 2" shows how the JNI ties the C side of an application to
the Java side. We designed an application with NDK and JNI,
and compared with the designed application using only Java.
Method.c

Application

Java Side C Side Figure 3. Architecture of applications in native C.

--I Exceptions
Applications include five different algorithms (JNI delay,
Integer & Floating-point calculation, Memory access, String

Functions 1 J Processing). Each algorithm was implemented as follows. The

-I
�--------,

N Classes
first one is the JNI delay. JNI delay occurs when a native
__

L--__--'
method is called. Therefore, JNI delay is measured before all
Libraries 1-- I other experiments[8]. Second, we measured the integer
L-___--'
- IL _ _v_M
__-,
calculation time using Fibonacci sequence that consists of only
integer arithmetic. Recalculated after initializing if an Integer
gets out of range. Third, we measured the execution time of
Floating-point processing using the circle area calculation
Figure 2. Architecture of JNI(Java .. C, C++). algorithm that returns the area of a circle whose radius is r. In
the fourth experiment, the memory access time is measured by
using the worst-case scenario of bubble sort. Finally, we
III. EXPERIMENTS measured the time of String processing. It measures the
processing speed of the String by the continuous String input.
In this paper, experimental equipment for performance We used 'nanoTimeO' method in Java (Since JDKI.5) for
evaluation is as follows: Intel Core i5 760 2.8GHz and 3.0GB more accurate measurements. It returns the current value of the
memory. In addition, the experiment was performed on an most precise available system timer, in nanoseconds. This
Android virtual emulator. The emulator target version is method also can only be used to measure elapsed time and is
Android 2.3(API level 9/Gingerbread), and native method was not related to any other notion of system or wall-clock time.
designed using the NDK R5b. The value returned represents nanoseconds since some fixed
but arbitrary time. In other words, This method provides First, JNI delay is about 1. 14 microseconds. It is a slight
nanosecond precision, but not necessarily nanosecond delay, and it does not greatly differ from no-operation delay.
accuracy[9]. In this application, the source code for execution "Fig. 5" shows the results of the Integer & Floating-point
time measurement is shown below. execution time.

long startTime = System.nanoTimeO; Integer & F loating point(Java vs Native C)


� .-------�-
1* Running the algorithm source code 35 +-------+--
for performance evaluation . . . *1 30+-----��-
� 25 +-------���- � Fibonacci java
long endTime = System.nanoTimeO;
� 20 +----------------.��----­ ..... Fibonacci ndk
<Il

o
long estimatedTime = endTime - startTime; � 15 +---------------+-+---��- ""*"Floating point(pi) java
10+-------------����----- -+-Floating point(p� ndk
<Il

"Fig. 4" shows designed applications for performance


evaluation. This application consists of five tabs for each
performance evaluation as described above. Furthermore, there
are two buttons in each tab. One is button for measuring the
500 2500 5000 7500 10000 20000 3000040000 50000
execution time of native C algorithm, and the other one is
Loop counts
button for measuring the execution time of java
algorithm(method). Figure 5. Integer & Floating-point procesing time.

The x-axis and the y-axis of the graph represent loop counts
and execution time in milliseconds, respectively. We can see
that Integer arithmetic is faster than Floating-point operations.
Besides, the Native C code is faster than Java code. It means
that we can achieve better performance if we use the Native C
when we design application included many Floating-point
operation such as game and graphic processing.

Memory access(Java vs Native C)


350000 -,------

3� +-------�P_
s: 250000 +-------+--

�. 2� +----+-

g
()
150000 +-------/---­ --Memory access java
a...
Figure 4. Performance evaluation. --Memory access ndk
� 1� +----�r-
50000 +----�--=_
IV. RESULIS AND ANALYSIS

All of the above experimental result was calculated using ",<§> f><§> "'<§>� ,\",<§> # # #'
"" '); "i

the harmonic mean. The harmonic mean is one form of Loop counts
average, which is appropriate for situations when the average
Figure 6. Memory access time.
of rates is desired[lO). The harmonic mean H of the real
numbers xl, x2, ... , xn > 0 is defined as follows.
The "Fig. 6" shows the measurement results of memory
access time. "Fig. 6" also shows that Native C is faster than the
Java. In addition, the deviation between Native C and Java
becomes greater(X 9.2) as the number of memory accesses
increase. It means that using Native C is more efficient in case
( 1) of an application where memory access occurs frequently.

It is also more apparent that the harmonic mean is related to String processing measurement results are shown in "Fig.
the arithmetic and geometric means. In this paper, the average 7". In contrast to the above results, the performance of the Java
processing time of each algorithm was calculated using the string processing code is better than that of Native C code. This
above formula (n=lOO) for more accurate measurements. is reason that Java, CIC++ language and IN! String processing
type are different each other. (Java : Unicode, CIC++ : KSC
560 1, JNI : UTF-8) So, type conversion is needed. Therefore, operations. Especially, Native C shows the best performance in
Java language is more efficient when design an Android the memory access operation. On the other hand, Java language
application which included many String processing. is more efficient when design an Android application that
includes many String processing because Java language does
String test(Java vs Native C) not require type conversion of strings.
120

100
REFERENCES

!S:
80
'" [I] Chia-Chi Teng, Richard Helps, "Mobile Application Development :
ro
(1 Essential New Directions for IT", School of Technology, Brigham
0 60
:::J String java Young University, April, 2010.
0..
'"

-t- ---1'-- -- String ndk [2] Stephen D. Drake, "Embracing Next-Generation Mobile Platforms to
40
_
____________

Solve Business Problems", Sybase White Paper, Oct 2008.

20
[3] Android(Operating System)
http://en.wikipedia.orglwiki/Android_(operating_system).
0 [4] OHA(Open Handset Alliance) http://www.openhandsetalliance.coml.
25 50 75 100 200 3 00 400 500 [5] Official Android developers website http://developer.android.com.
Loop counts [6] Sheng Liang. The Java Native Interface : Programmer's Guide and
Specification, Addison-Wesley, 1999.

Figure 7. String processing result. [7] Java Native Interface(JNI)


http://en.wikipedia. orglwiki/Java_Native_Interface.
[8] Dawid Kurzyniec and Vaidy Sunderam, Efficient Cooperation between
V. CONCLUSIONS Java and Native Codes - JNI Performance Benchmark, Emory
University Dept. of Math and Computer science.
[9] Java nanoTime
In this paper, we have programmed Android applications
http://download.oracle.comljavase/l.5.0/docs/api/javailangiSystem.html.
using Java and Native C, and compared the performance
[10] Harmonic mean http://en.wikipedia. orglwiki/Harmonic_mean.
between the two languages. As a result, Native C was faster
than the Java in Integer, Floating-point and Memory access

You might also like