I was changing my for loop to increment using ++i
instead of i++
and got to thinking, is this really necessary anymore? Surely today\'s compilers
There are three quotes I believe that every developer should know with regard to optimization - I first read them in Josh Bloch's "Effective Java" book:
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity.
(William A. Wulf)
We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.
(Donald E. Knuth)
We follow two rules in the matter of optimization:
Rule 1: Don't do it.
Rule 2: (for experts only). Don't do it yet - that is, not until you have a perfectly clear and unoptimized solution.
(M. A. Jackson)
All these quotes are (AFAIK) at least 20-30 years old, a time where CPU and memory meant much more than today. I believe is right way to develop software is first to have a working solution, and then use a profiler to test where are the performance bottlenecks. A friend once told me about an application that was written in C++ and Delphi, and had performance issues. Using a profiler they found out that the application spent a considerable amount of time converting strings from Delphi's structure to the C++ one and vice versa - no micro optimization can detect that...
To conclude, don't think that you know where the performance issues will be. Use a profiler for this.