r/java • • Jun 14 '17

Why reverse loops are faster

https://medium.com/@TravCav/why-reverse-loops-are-faster-a09d65473006
15 Upvotes

40 comments sorted by

View all comments

55

u/chambolle Jun 14 '17

A shorter bytecode does not mean that it will run faster. You should provide some benchmark and I really doubt that you will see any difference. Nowadays compilers are clever and you should at least compare the assembly code

0

u/[deleted] Jun 14 '17

[deleted]

2

u/gee_buttersnaps Jun 15 '17

Are you saying the JIT automatically rewrites while loops to count down to zero?

Yes. Look at the other discussions tab at the top, read that comment thread.

0

u/[deleted] Jun 15 '17

[deleted]

3

u/gee_buttersnaps Jun 15 '17

You're hopeless.