Android code performance optimization skills (1)

Source: Internet
Author: User
We all know that For Android 2.2Of JITPerformance has been substantially improved, but for older versions of Programs JavaExecution efficiency also has many language features, In Java 1.5Then there will be significant improvements. The following example is from SDK:
Static class Foo {int msplat;} Foo [] marray =... // The execution result and performance of the above static class Foo are divided into three methods: zero, one, and two for comparison. Public void zero () {// Most people may simply write int sum = 0; For (INT I = 0; I <marray. length; ++ I) {sum + = marray [I]. msplat ;}} public void one () {// improve the performance through local objects int sum = 0; Foo [] localarray = marray; int Len = localarray. length; For (INT I = 0; I <Len; ++ I) {sum + = localarray [I]. msplat ;}} public void two () {// recommended method. The new syntax feature of Java 1.5 can greatly improve the performance of int sum = 0; For (foo a: marray) {sum + =. msplat ;}}

Zero () slowest,One () Faster,Two () is the fastest, I hope this will help you.

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.