Performance of Android ndk

Source: Internet
Author: User
ArticleDirectory
    • This article Reprinted from http://blog.csdn.net/fangyuanseu/article/details/6875702
This article Reprinted from http://blog.csdn.net/fangyuanseu/article/details/6875702

Android ndk Learning

Today, I saw a paper from Smecta, South Korea. It has no theoretical value, but it is of great guiding value to developers, this article is about the performance difference between the Android Application Development ndk method and the Java method (using the sameAlgorithm), They focused on the performance impact of these aspects:

1 Integer Operation

2 Floating Point Calculation

3. Memory Access Performance

4 allocate heap Algorithm

At the beginning of the article, I first talked about several concepts: Android ndk and JNI. I will not write them here.

 

Lab environment: they are an experiment on the android simulator on the PC. PC: AMD athlon II X2 245 2.9 4.0 GHz, 2.1 GB memory simulator: Android (apilevel 7) with the android ndk R3 version

1 Integer Operation

Experimental Method: measure the time of the Algorithm for Finding Prime numbers. The value returned by this algorithm is the prime number in the input n integers.

Experiment results:

The X axis indicates the number of input integers, And the Y axis indicates the algorithm execution time (unit: MS)

From the above figure, we can see that the ndk method is much more efficient than the Java method (running on Dalvik), and the larger the gap between the two, the more input data.

2 floating point operations:

Experimental Method: Include the math. h header file, and then use the sine and Cosine Functions to calculate the floating point number algorithm. the return value of this algorithm is the sum of cosine and sine values from the zero degree to the input angle.

Experiment results:

The X axis indicates the input angle, and the Y axis indicates the algorithm execution time (unit: MS)

The experimental results show that the difference between floating point numbers is not too large.

3. Memory Access Algorithm

Experimental Method: In the heap memory, the worst case of Bubble Sorting is that the time complexity is O (n2 ).

Experiment results:

The X axis indicates the length of the input integer array, and the Y axis indicates the algorithm execution time (unit: MS ).

This experiment shows that there is a huge gap between the two in heap memory access.

4 heap memory application algorithm

Test method: Calculate the heap memory time for applying a 4 K multiple.

Experiment results:

The X axis represents a multiple of 4 K, and the Y axis represents the time consumed by the application (unit: MS ).

Experimental results show that the ndk method is much faster.

Generally, the Java language in the heap is used to apply for dynamic memory when creating objects in C/C ++.

Dynamic Application memory is used to avoid Memory waste. Compared with static application, dynamic application memory is slow, and there is a risk of Memory leakage and memory depletion.

Although dynamic application memory is much faster, it should be used with caution as a C/C ++ developer.

Summary:

A quantitative analysis is made on the impact of Android ndk and Java performance in four aspects, which is of great reference to developers, during development, we can determine when to use ndk and Java based on the above data, but we must consider the ndk method to makeCodeThe fact that the complexity increases.

My personal significance is that we can use the ndk Method to Improve the Performance of 3D graphics rendering on Android, because a 3D surface with a slightly complex point has a considerable number of vertex and index.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.