Chapter VII: Appendix: E
Program Efficiency
The following information may be of interest to programmers desiring an efficient program:
1. The FOR statement is defined with more generality than is useful in
most programs. In particular, the arithmetic expressions in the FOR
clause are allowed to change in value during execution of the FOR
statement. The compiler does not attempt to determine which FOR
statements make use of this flexibility and treats all of them in the
most general way. Therefore, in a statement such as
for I := 1 step M + N until abs(A - B) do ... ,
the expression M + N is evaluated twice for each iteration, and the
expression abs(A - B) is evaluated once for each iteration. If M, N, A
, and B do not change in the loop, this is unnecessary. Such
inefficiency can be avoided by programming in a slightly different
way. The above example can be written as follows:
T1 := M + N; T2 := abs(A - B) ;
for I := 1 step T1 until T2 do ... .
2. The concept of call by value is a device applied to procedures to
eliminate unneeded flexibility in procedure calls. If a parameter
having a value is referenced more than once in the procedure body and
the flexibility of call by name is not needed, then the program is
more efficient if the parameter is included in the value part of the
procedure heading. If such a parameter is referenced only once, it is
more efficient if it is not included in the value part.
3. Array identifiers which are parameters should be specified.
Comments
Log in to leave a comment.
The Oak Ridge ALGOL Compiler for the Control Data Corporation 1604Chapter VII: Appendix: E
0%1 min left in chapter