PERFORM statements are generally very efficient, although you can increase their performance in a number of ways.
Using PERFORM statements is a very good way of keeping the size of your program down as well as giving it an easy-to-maintain structure. The following rules enable you to use PERFORM in the most efficient ways.
- Put commonly used pieces of code in sections and perform them.
Apart from being good coding practice, this saves space.
- When you increment or decrement a counter, terminate it with a literal value rather than a value held in a data item. For example, to execute a loop
n times, set the counter to
n and then decrement the counter until it becomes zero, rather than incrementing the counter from zero to
n.
- Perform sections, not paragraphs. Put EXIT PROGRAM and STOP RUN statements at the end of the first (main) section.
The range of an out-of-line PERFORM statement should not contain the end of another perform range. If it does, the program is said to trickle, that is execution is allowed to go past the end of a perform range. Applying the rule above ensures that this does not happen.
For example, see
Example of Inefficient Use of the Perform Statement for an example of bad practice.
- Only use GO TO for paragraphs in the same section.
- Do not use PERFORM ... THRU statements.
- Do not use ALTER statements. The presence of an ALTER statement in a program prevents optimization of PERFORM statements.
- Code a STOP RUN statement immediately after CALL statements that you know execution will not return from; for example, calls to programs that will tidy up and terminate an application. This technique ensures that there is no trickle effect in execution and also enables the Compiler to produce better code, in terms of run-time performance and analysis.