MCIT Technical Newsletter #1

COBOL INSPECT Verb Performance


        The INSPECT verb, as implemented by the IBM COBOL II compiler, can
     be extremely CPU intensive which can cause programs to run far longer than
     necessary.  Surprisingly, simply changing the INSPECT … REPLACING to a
     PERFORM … VARYING, which examines each byte and replaces it if necessary,
     can make a significant improvement in performance.
There is an even better solution to this problem. There is a module, written in assembler language, that utilizes the old system 360 TR (translate) instruction to do the required data manipulation both efficiently and expediently. The module id is DR0139BA and it is located in the ‘NLAPPL.BATCH.LOADLIB’ PDS.
DR0139BA is called dynamically from a COBOL II program which passes the address of the object that requires examination, the length of that object, the character to look for, and the character to replace it with. The example code segments that follow show exactly how to define these parameters and how to pass them to the subroutine. Data Division ... 01 TEST-RECORD. 02 PIC X(20000) VALUE LOW-VALUES. 01 CALLED-MODULES. 02 DR0139BA PIC X(08) VALUE ‘DR0139BA’. 01 WORK-VARIABLES. 02 RECORD-LENGTH PIC S9(08) COMP VALUE 20000. 02 E-R-SET. 03 FROM-CHARACTER PIC X(01) VALUE LOW-VALUE. 03 TO-CHARACTER PIC X(01) VALUE SPACE. Procedure Division ... CALL DR0139BA USING TEST-RECORD RECORD-LENGTH E-R-SET. A test program was used to indicate the approximate improvement that can be expected when using these alternatives to the INSPECT verb. The test program used a 20000 byte record in working-storage, initialized to low values. The system clock was printed before and after each alternative was executed. The INSPECT verb was used to replace each low value by a space and then replace each space by a low value 1000 times. A PERFORM … VARYING loop was done to accomplish the same task 1000 times. Finally DR0139BA was called to do the same process 1000 times. The time required for the DR0139BA is slightly inflated because the test program also verified that the translation was correct by comparing the test record to two records in working storage that were initialized to low values and spaces respectively.

The elapsed times from this test are: INSPECT ................... 1 min 52.32 secs PERFORM VARYING ........... 0 min 24.22 secs (5x faster) DR0139BA .................. 0 min 00.82 secs (30x & 137x faster) The test program may be used to verify these results. The source program is ‘H308.SPF.SOURCE(TESTPGM)’ and the JCL is ‘H308.SPF.JCL(TESTPGM)’. Please note that results will vary based on the load on the system and any changes in the actual CPU, but the relative magnitudes of elapsed time will remain similar.