Code can be optimized in many ways, to achieve different goals.
1. For execution speed (algorithmic cost reduction, bottleneck optimization, low-level optimization),
2. For resource use (memory, internet throughput, internet resources, printers etc...),
3. For lines of code (the less lines of code, the less errors),
4. For scalability (hardware cost is often less expensive than software costs.. it's cheaper to buy few computers than to invest into more years of development),
5. For change management costs (programmers' time are important costs, for it allows for quicker changes of software in response for reality changes),
6. For risk reduction (when costs of failure, such as in space program, are enormous),
7. For ease of technology change (when we do not wish to depend on certain vendor[s]).
and so on ....
See also: Code should be independent, Few thoughts on code quality (for professionals).