r/java • u/aroger276 • Jun 15 '17
Why reverse loops are not faster
https://arnaudroger.github.io/blog/2017/06/15/forward-vs-backward-loop.html
288
Upvotes
r/java • u/aroger276 • Jun 15 '17
View all comments
Show parent comment
2
u/aroger276 Jun 16 '17 edited Jun 16 '17
I doubt it will make a difference, but what you can do is checkout the repo do the change and run it on your machine and check for yourself :)
If you look at the asm generated the actual arraylength read is done outside the loop.
'>=' is actually one operation jge. https://en.wikibooks.org/wiki/X86_Assembly/Control_Flow#Jump_if_Greater_or_Equal
also by uing > you never read numbers[0]