Solved Question Papers Q-25
3. a. The following techniques are explained with an example that is used for tuning the
code.
(1) Collect common sub expressions. If an expensive computation appears multiple
times, do it in only one place and remember the result. For example, calling sqrt
twice in a row with the same values; in effect, the computation was
TRSUEYXEYEZXEZTRSUEYDEYEZXEZ
Compute the square root once and use its value in two places.
(2) Replace expensive operations by cheap ones. This is used by replacing
multiplications by additions or shifts. Division and remainder are much slower than
multiplication. However, there may be improvement if a division can be replaced with
multiplication by the inverse or a remainder ...