I/O operations are the slowest part of a program, because disk drives are not nearly as fast as memory. You can speed up a program by replacing disk operations with operations to memory or by eliminating unnecessary disk operations.
Suppose you have an employee master file that has a department number field telling which department an employee works in; a department master file keyed on department number, which also identifies the department; and a payroll program that reads the employee master file sequentially and chains to the department master file to get the department description (see 4).
Suppose you have an employee master file that has a department number field telling which department an employee works in; a department master file keyed on department number, which also identifies the department; and a payroll program that reads the employee master file sequentially and chains to the department master file to get the department description (see Figure 4).
To speed up this application, use a memory operation instead of a disk operation. Replace the random reads (RPG CHAIN) with array lookups. Read the entire department master file into an array at program initialization. Then, instead of chaining to the department master file to determine the department, look up the department in the array as shown in 5.
To speed up this application, use a memory operation instead of a disk operation. Replace the random reads (RPG CHAIN) with array lookups. Read the entire department master file into an array at program initialization. Then, instead of chaining to the department master file to determine the department, look up the department in the array as shown in Figure 5.
Another technique is to eliminate any unnecessary file I/O. If your file is too big to fit in a table or array, or you usually only access a few records, chain only if necessary. Save the department number in a variable, and chain only if the department number in an employee master record is different from the one saved in the variable, as shown in 6.
Another technique is to eliminate any unnecessary file I/O. If your file is too big to fit in a table or array, or you usually only access a few records, chain only if necessary. Save the department number in a variable, and chain only if the department number in an employee master record is different from the one saved in the variable, as shown in Figure 6.
I/O Speed Demons
Figure 4 Sample Application
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FEMPMAST IF E K DISK FDPTMAST IF E K DISK * C READ EMPREC LR C *INLR DOWEQ*OFF * C EM#DPT CHAINDPTREC 99 C *IN99 IFEQ *OFF . . . C ENDIF * C READ EMPREC LR C ENDDO
I/O Speed Demons
Figure 5 Reducing I/O with Array Lookups
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 C EM#DPT LOKUPDPT,X 99 C *IN99 IFEQ *OFF . . . C ENDIF
I/O Speed Demons
Figure 6 Reducing I/O with a Save Field
*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 C EM#DPT IFNE SAVDPT C EM#DPT CHAINDPTREC 99 C *IN99 IFEQ *OFF . . . C ENDIF C MOVE EM#DPT SAVDPT C ENDIF
LATEST COMMENTS
MC Press Online