To Index or Iterate

Video about loops performance

Make it work, make it right, make it fast

Naive tests

Pure Java

A graph of execution time of loops by given input strings count
A graph of execution time of loops for 16K strings clustered by attempts

Android

A graph of execution time of loops by given input strings count
A graph of execution time of loops for 6K strings clustered by attempts

Only loops test

  • running Android One device — I don’t have one, but I will test it in Google Nexus 4 emulator;
  • lists contain 400K random integers — I will allow myself to test it on 4M random integers
  • list is walked 10 timesokey
  • min & max times are through out — okey
A graph of execution time of loops for 4M integers clustered by attempts
for (int i = 0; i < integers.size(); i++) {
Object object = integers.get(i);
//...
}
int size = integers.size();
for (int i = 0; i < size; i++) {
Object object = integers.get(i);
//...
}

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store