Let's first take your case: PHP
- I don't think PHP is a kind of language (both because of it'sits nature and it'sits main domain of application) that you need to worry about these "micro-optimizations". PHP code is mostly optimized with opcode caching.
- The programs written in PHP are not CPU bound, they're mostly IOI/O bound, so these optimizations won't be worth your time anyway.
- anythingAnything that you MUST optimize should probably be snuck into a C extension and then dynamically loaded in the PHP runtime
- So as you can see, we get no incentive by micro-optimizing our code in PHP -- on the other hand, if you spend that time in making PHP code more readable and maintainable -- that will pay you more dividends.
In general,
I wouldn't spend "TOOOOO" much time optimizing my code in a dynamic language like PythonPython or Ruby Ruby -- because, they are NOT designed for CPU intensive number-crunching tasks. They solve different class of problems where modelling a real world situation in an elaborate manner (which is easy to read and maintain) -- which is called expressivity -- is more important than speed. If speed were the prime concern, they wouldn't be dynamic in the first place.
For compiled programms (C++, Java), optimization is more crucial. But there too, first you have to look at the nature/domain/purpose of the program you're writing. You should also carefully weigh the time to micro-optimize against the gains from that optimization. If you need even more optimization, then you may as well consider going a step downward -- and code those pieces of your code in assembler.
So, to answer your original question -- "Is micro-optimisation important when coding?" -- the answer is -- it DEPENDS --
- whatWhat kind of thing you're doing: application domain, complexity?
- areAre microsecond speed improvements REALLY important for your program?
- whatWhat sort of optimization will be most gainful -- it? It may not always be code optimization, but something external.
- howHow much "goodness" (in terms of speed) you're reaping out of the time you invest micro-optimizing?
- canCan better speeds be achieved in other ways -- by changing the hardware, RAM & processor, executing code parallelly, or on a distributed system?
Not only is micro-optimization (code optimization for that matter) is time consuming, it "distorts" the natural readability of your code, thus making it maintenance heavy-heavy. Always consider it a last resort -- always try to optimize the entire application by adopting better hardware and better architecture than optimizing individual code files.