you probably often thought about what is the fastest/most efficient way of looping...
So according to the DalvikVM designer Dan Bornstein these are the fastest ways of looping, sorted from fast to slow. (If you do it like 1, 2 or 3 you should not worry)
Using java Syntax Highlighting
- // 1 (fastest)
- for(int i = initializer; i >= 0; i--){ ... }
- // 2
- int limit = calculateLoopLimit();
- for(int i = 0; i < limit; i++){ ... }
- // 3
- Type[] array = getMyArray();
- for(Type obj : array){ ... }
- // 4
- for(int i = 0; i < array.length; i++){ ... }
- // 5
- for(int i = 0; i < this.var; i++){ ... }
- // 6
- for(int i = 0; i < obj.size(); i++){ ... }
- // 7 (slowest)
- Iterable<Type> list = getMyList();
- for(Type obj : list){ ... }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
This is where I extracted that information from (jump to minute ~40):
[align=center][youtube]http://www.youtube.com/watch?v=ptjedOZEXPM[/youtube][/align]
Regards,
plusminus





especially with a small number of sheet, for-each works much better for me... so I returned to it.
I just 