List Loop traversal performance comparison in Android

Source: Internet
Author: User

In Android development, only a list-style interface, we almost all need to use list to store data, in a very small list words almost no matter what kind of loop traversal in general performance is no different. However, when we encounter a slightly larger amount of data, it is necessary to consider which method of writing is more high performance.
The following three types are common:
First Kind

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

Another kind

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

Third Kind

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

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

Statement: The above environment in the MacBook Pro, Eclipse-Android5.0-NEXUS5 mobile phone environment test results, Google below the data show in the case of non-JIT in fact the first is the fastest, But in the Android environment or another one is the best performance choice.

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.