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.