Common Subexpression Elimination - Example

Example

In the following code:

a = b * c + g; d = b * c * d;

it may be worth transforming the code to:

tmp = b * c; a = tmp + g; d = tmp * d;

if the time cost of storing and retrieving "tmp" outweighs the cost of calculating "b * c" an extra time.

Read more about this topic:  Common Subexpression Elimination

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)