Do you care about micro-optimizations? While writing code do you always compare the speed of two similar functions/libraries/routines and use the one which is more performant (even if it makes little difference to overall speed of the app)?
You don't micro-optimize while writing code.
You take performance concerns into consideration, and you absolutely avoid writing code that's obviously slow or stupid.
You add ways to instrument/measure/profile parts of your code and you measure performance early and often to catch performance problems early.
It's important to define what is "micro-optimization" because many people take the notion of "don't micro-optimize" and extend it to imply "don't worry about performance". This is a bad approach. Not worrying about performance leads to bad performance.
Micro-optimization means taking extra steps to shave off 5 or 10 or 50 cycles of instructions. This is not always a bad thing. If you are inside a tight loop then every cycle counts. But the problem with this approach is that if you program "depth-first" you will not get things done. You need to know when something is good enough and move on to the next thing. You can then come back later and "micro-optimize" the shit out of it later.
Generally speaking for most business applications that are not performance driven you don't need to do micro-optimization. While we all want to write the most efficient code possible writing CLEAR and CONCISE code is much more important and should be your primary focus during the development phase of the cycle. Afterwards you can come back and optimize if needed. Good luck!
I think that micro-optimizations are generally not very important, unless you're writing extremely computationally tasking code. Why? Because computers can complete thousands of operations in extremely short times, and most users won't even notice or see the effects of most micro-optimizations.
There are some cases, of course, when software should be optimized. For example, if you have very computationally tasking code that is repeating many times, optimization would probably be a good idea to save energy and (if code is being run client-side) CPU usage.
I hope this helps!
It's very important... not to do that.
There are a few reasons:
There are exceptions (3% according to Donald Knuth). For example, implementing a different algorithm with better runtime complexity if you think it'll be critical. In such a case, optimizing it later may be a complete rewrite. But then that's not really a micro-optimization.
Micro-optimization are the road of the devil. Don't think about it.
Why ?
Because, when the time to talk about performance is coming there is the process (note the first step please) :
Micro-optimization leads on hard-to-read/follow/understand code, bugs, time consuming ... AND, not the least, it's really annoying to write optimized code !
Cheers ! 🍻🍻
Somewhat. The idea is to not put any expensive fn,lib, object creation etc. But you shouldn't spend too much time on it. Just keep it in mind while writing code.
Premature Optimisation simply increases the time taken to complete a project, and gain isn't that much.
Benchmark the project after you have completed your functionality, and figure out the most expensive part, and then optimise it.
Paddy McCarthy
A Python programmer and Rosetta Code contributor
Of course not. run time is a quality metric that should be defined. Hit it and you are fine. you loose quality if you hammer speed at the expense of other metrics. if you don't know how fast is fast enough then back to th drawing board. Do you need an Intel Xeon 50 processor workstation or an Arduino? A raspberry pie or a custom ASIC? You don't know you are optimising unless you have a goal. pass your goal and further speed gains are likely to be a waste of resources and money.