The three rules of optimization

Optimization has a price, no matter what the results are. And the most important cost of optimization apart from the obvious development time is the increase in software complexity and reduction in maintainability. When a piece of code works, it might be better (sometimes) to leave it alone than to try making it faster at all costs. This means that if the optimization process has to be cost-effective, it must be done reasonably. The following are the three most basic optimization rules to keep in mind when doing any kind of optimization:

In the following sections, we will explain these rules in detail.