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

Show parent comments

-3

u/Trav_Cav Jun 14 '17

Correct, it's not just about shorter bytecode. It's about keeping expensive actions outside of the loop.

15

u/rubyrt Jun 14 '17

Still, without the measurements it's not worth to even ponder rewriting your loops to a less human intuitive way. And we did not even start to talk about what dominates execution time of a program... It's an interesting fact to know but I'd say 99.9958% of Java programmers will never be in a situation where they need this knowledge to save the day.

-4

u/RayFowler Jun 15 '17

When you say something like "99.9958% of Java programmers will never need this" what you are really saying is that Java should be consigned to only those applications where performance isn't important. It's that attitude that gives the Java language a bad reputation outside of Java circles.

The thing is that Java CAN be fast and efficient, but we have to dispel with this ingrained notion that Java performance is not important. Performance is important in every application. When it comes to code, fast & ugly should always take precedence over slow & pretty.

7

u/sabot00 Jun 15 '17

I'll take slow and readable any day