0% found this document useful (0 votes)
67 views2 pages

Code Optimization

Code optimization is a program transformation technique that aims to improve code performance by making it more efficient in its use of resources like CPU and memory, while delivering higher speeds. It involves replacing high-level programming constructs with lower-level, more efficient code without changing the program's meaning. Optimization should both increase a program's speed and reduce its resource usage, while not slowing down the overall compiling process itself. Efforts for optimization can occur at different stages of compilation, from rearranging code and algorithms to modifying intermediate code and optimizing for a target machine's memory hierarchy and registers. Optimization is broadly categorized into machine-independent and machine-dependent types.

Uploaded by

Jerry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views2 pages

Code Optimization

Code optimization is a program transformation technique that aims to improve code performance by making it more efficient in its use of resources like CPU and memory, while delivering higher speeds. It involves replacing high-level programming constructs with lower-level, more efficient code without changing the program's meaning. Optimization should both increase a program's speed and reduce its resource usage, while not slowing down the overall compiling process itself. Efforts for optimization can occur at different stages of compilation, from rearranging code and algorithms to modifying intermediate code and optimizing for a target machine's memory hierarchy and registers. Optimization is broadly categorized into machine-independent and machine-dependent types.

Uploaded by

Jerry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Code Optimization

Optimization is a program transformation technique, which tries to improve


the code by making it consume less resources (i.e. CPU, Memory) and
deliver high speed.
In optimization, high-level general programming constructs are replaced by
very efficient low-level programming codes. A code optimizing process must
follow the three rules given below:

The output code must not, in any way, change the meaning of the program.

Optimization should increase the speed of the program and if possible, the program should demand less number
of resources.

Optimization should itself be fast and should not delay the overall compiling process.

Efforts for an optimized code can be made at various levels of compiling the
process.

At the beginning, users can change/rearrange the code or use better algorithms to write the code.

After generating intermediate code, the compiler can modify the intermediate code by address calculations and
improving loops.

While producing the target machine code, the compiler can make use of memory hierarchy and CPU registers.

Optimization can be categorized broadly into two types : machine


independent and machine dependent.

Machine-independent Optimization
In this optimization, the compiler takes in the intermediate code and
transforms a part of the code that does not involve any CPU registers
and/or absolute memory locations. For example:
do
{
item = 10;
value = value + item;
} while(value<100);

This code involves repeated assignment of the identifier item, which if we


put this way:

Item = 10;
do
{
value = value + item;
} while(value<100);

should not only save the CPU cycles, but can be used on any processor.

Machine-dependent Optimization
Machine-dependent optimization is done after the target code has been
generated and when the code is transformed according to the target
machine architecture. It involves CPU registers and may have absolute
memory references rather than relative references. Machine-dependent
optimizers put efforts to take maximum advantage of memory hierarchy.

You might also like