The translation of a source program to an object program is basically one of many mappings; that is, there are many object programs for the same source program, which implement the same computations . Some of these object-translated source programs may be better than other object programs when it comes to storage requirements and execution speeds. Code optimization refers to techniques a compiler can employ in order to produce an improved object code for a given source program.
How beneficial the optimization is depends upon the situation. For a program that is only expected to be run a few times, and which will then be discarded, no optimization is necessary. Whereas if a program is expected to run indefinitely, or if it is expected to run many times, then optimization is useful, because the effort spent on improving the program's execution time will be paid back, even if execution time is only reduced by a small percentage.
What follows are some optimization techniques that are useful when designing optimizing compilers.