CE532
Chapter 3

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.

  1. 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.
  2. 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.
  3. In loops and iterations, the quantities that do not vary in the loop should be calculated outside the loop.
  4. Personal computers can perform a decrement operation more quickly than a comparison.

 

Hojjat Adeli, Professor
Department of Civil & Environmental Engineering and Geodetic Science
The Ohio State University 
409 Hitchcock Hall, 2070 Neil Avenue, Columbus OH 43210