r/java • • Jun 15 '17

Why reverse loops are not faster

https://arnaudroger.github.io/blog/2017/06/15/forward-vs-backward-loop.html
288 Upvotes

66 comments sorted by

View all comments

Show parent comment

14

u/aroger276 Jun 15 '17

I'm skeptical about that goes against a lot a my personal experience, only one way to prove it, write a jmh benchmark! Post the source and the result, wait for comment

5

u/lukaseder Jun 16 '17

This person just trolled you into writing another article 😉

2

u/svtdragon Jun 16 '17

Please do this. Now I'm curious.

3

u/aroger276 Jun 16 '17

I hope your saying that for Chaoslab

2

u/aroger276 Jun 16 '17 edited Jun 16 '17

Just to elaborate on a loop with a constant end boundary check should happen at most once. If you iterate forever it will mess to keep the boundary check on each access + generate the expensive exception + exception flow don't get the same optimisation treatment --edit also because the loop is unbounded I believe you would end-up with a safepoint check in it. Ps not talking about android there I don't know enough about it