|
3.3
HOW TO WRITE EFFICIENT PROGRAMS
A
list of guidelines for developing efficient software on personal
computers is presented in this section. Some of these guidelines
are in contradiction with the principles of structured programming
section 3.2. As the programs become larger, one may have to compromise
some of the principles for the sake of increased efficiency.
- On
most available personal computers, division and multiplication
take 10 to 100 times more CPU time than addition and subtraction.
Therefore, unnecessary divisions and multiplications should be
avoided.
- On
personal computers integer arithmetic is an order of magnitude
faster than floating-point arithmetic. To increase the efficiency
of the program, especially in graphics software, integer arithmetic
should be preferred over the floating-point arithmetic.
- In
loops and iterations, the quantities that do not vary in the loop
should be calculated outside the loop.
- Personal
computers can perform a decrement operation more quickly than
a comparison.
|