Comparison of List loop traversal performance and Android performance in android

Source: Internet
Author: User

Comparison of List loop traversal performance and Android performance in android

In android development, we almost all need to use List to store data as long as it is a simplified style interface. If there is a small number of lists, almost any loop Traversal method can have no overall difference, however, when we encounter a small amount of data, it is necessary to consider which method of writing is relatively high performance.
There are three common types:
First

For (String s: tests ){//....}

Second

Int size = tests. size (); for (int I = 0; I <size; I ++) {tests. get (I );}

Third

Iterator <String> it = tests. iterator (); while (it. hasNext () {it. next ();}

When the above three types of data are less than or equal to 100 of the data, the output time is almost zero, when it is around 1000, the third method is slightly slower than 1 ms <probably due to the current environmental reasons> it can be said that there are no differences between the three methods, when the data volume is about 10000, we can see the difference between the first and the third is about 4 ms, and the second is about 2 ms. When the data volume is about 100000, the first is about 40 ms, the second is 17 ms, and the third is 33 ms.

Statement: The test results in the above environment are in the MacBook Pro-> Eclipse-> Android5.0-> Nexus5 mobile phone environment. The following Google documents show that the first one is the fastest in non-JIT scenarios, however, in the Android environment, the second type is the best performance choice.

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.