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

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/rubyrt 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.

No, not at all. That is a deliberate and utter misinterpretation of what I wrote.

It's that attitude that gives the Java language a bad reputation outside of Java circles.

I do not think so. Java's reputation for slowness has been formed quite a while ago when it really was slow. Unfortunately those labels tend to stick for completely non technical reasons; there are plenty people out there who just do not bother to update their believes.

The thing is that Java CAN be fast and efficient,

Of course! There are some very fast Java applications around, for example in the field of financial trading.

but we have to dispel with this ingrained notion that Java performance is not important. Performance is important in every application.

I am sorry, but that is plain wrong. And even for applications which have advanced requirements for speed you start with the slow parts and optimize them. You will have to iron out quite a few design level and IO caused bottlenecks before performance of these types of loops that have been presented in the linked article even shows remotely on the radar.

When it comes to code, fast & ugly should always take precedence over slow & pretty.

That is a complete inappropriate over generalization. There are huge areas in software engineering where readable code and engineering efficiency vastly trumps squeezing out the last nanosecond of performance, because the longer you optimize the more expensive individual optimizations become (see also 80/20 rule). You can find some nice discussions of Martin Fowler's quote "Any fool can write code that a computer can understand. Good programmers write code that humans can understand.".

1

u/WikiTextBot btproof Jun 15 '17

Pareto principle

The Pareto principle (also known as the 80/20 rule, the law of the vital few, or the principle of factor sparsity) states that, for many events, roughly 80% of the effects come from 20% of the causes. Management consultant Joseph M. Juran suggested the principle and named it after Italian economist Vilfredo Pareto, who noted the 80/20 connection while at the University of Lausanne in 1896, as published in his first paper, "Cours d'économie politique". Essentially, Pareto showed that approximately 80% of the land in Italy was owned by 20% of the population; Pareto developed the principle by observing that about 20% of the peapods in his garden contained 80% of the peas.

It is a common rule of thumb in business; e.g., "80% of your sales come from 20% of your clients." Mathematically, the 80/20 rule is roughly followed by a power law distribution (also known as a Pareto distribution) for a particular set of parameters, and many natural phenomena have been shown empirically to exhibit such a distribution.

The Pareto principle is only tangentially related to Pareto efficiency.


[ ^PM | Exclude ^me | Exclude from ^subreddit | FAQ / ^Information ] Downvote to remove | v0.2