Reprinted from http://blog.csdn.net/leilu2008/article/details/6672979
We all know that the JIT performance of Android 2.2 has been improved substantially, but for older programs to improve Java Execution Efficiency There are many language features, for the Java 1.5 There will be significant improvements after that. The following example is from the SDK:
[Java]View Plaincopy
- Static class Foo {
- int Msplat;
- }
- foo[] Marray = ...
- The execution and performance of the Static class Foo above, we compare three methods zero, one and two.
- public void Zero () { ///Most people may simply write this directly
- int sum = 0;
- for (int i = 0; i < marray.length; ++i) {
- sum + = Marray[i].msplat;
- }
- }
- Public void One () { //improve performance with 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 () { ///recommended method, with new syntax features in Java 1.5 can greatly improve performance
- int sum = 0;
- for (Foo A:marray) {
- sum + = A.msplat;
- }
- }
Zero () slowest , one() faster, and both() the fastest, I hope these have some help for you.