List Loop traversal performance comparison in Android

Source: Internet
Author: User

In Android development, as long as the list-style interface we need to use lists to store data, in a very small list of almost any kind of loop traversal mode overall performance is no different, but when we encounter a slightly larger amount of data, it is necessary to consider which way to write more high performance.
The following three types are common:
First Kind

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

The second Kind

sizetests.size();fori0isizei{    tests.get(i);}

Third Kind

it = tests.iterator();    while(it.hasNext()) {        it.next();    }

Using the above three in the case of data volume less than or equal to 100, almost the output time is 0, when around 1000 of the time the third kind of slightly slower around 1ms < may be at the time of environmental reasons > can say three ways is also no difference, When the amount of data around 10000 we can see the difference between the first and the third kind of almost 4ms and the second as long as 2ms, when the amount of data in 100000 or so, the first kind of almost 40ms, the second 17ms, the third kind of 33ms.

Disclaimer: The above environment in the MacBook Pro, Eclipse-Android5.0, NEXUS5 mobile phone environment test results, Google the following information shows in the case of non-JIT in fact, the first is the fastest, But in the Android environment, the second is the best performance option.

List Loop traversal performance comparison in Android

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.