When doing an index vs subscript performance test, I use the the following to test relative performance.
In the examples below look at the "UNTIL" clause in the TEST009 program. When comparing an index to a numeric field, the compiler generates extra code to convert both to the same format. Remember than an INDEX is stored as a displacement so when comparing to a number the index has to be divided by the length of 1 entry of the array. Then it has to add 1 to that number. The logic to convert the index to a numeric value would distort the comparison.
Note that TEST009 uses an elementary USAGE INDEX field to eliminate this conversion every time thru the loop. Use the "LIST" compiler option and look at the generated ASSEMBLER code for the UNTIL clause.
a comparison which will show the difference is between TEST005 and TEST009 as they both use INDEXES. The only difference is the UNTIL clause.
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST001.
AUTHOR. CHUCK HAATVEDT
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SUB-1 PIC S9(9) COMP.
01 SUB-2 PIC S9(9) COMP.
01 TBL.
05 TBL-ENTRY-LVL-1 OCCURS 100000 TIMES
INDEXED BY TBL-1-INDEX.
10 TBL-ENTRY-LVL-2 OCCURS 10 TIMES
INDEXED BY TBL-2-INDEX.
15 TBL-TEXT-1 PIC X.
15 TBL-CHAR-1 PIC X.
PROCEDURE DIVISION.
PERFORM 050 TIMES
PERFORM VARYING SUB-1 FROM 1 BY 1
UNTIL SUB-1 > 100000
PERFORM VARYING SUB-2 FROM 1 BY 1
UNTIL SUB-2 > 10
MOVE SPACES TO TBL-TEXT-1 (SUB-1, SUB-2)
MOVE 'A' TO TBL-CHAR-1 (SUB-1, SUB-2)
END-PERFORM
END-PERFORM
END-PERFORM.
GOBACK.
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST002.
AUTHOR. CHUCK HAATVEDT
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SUB-1 PIC S9(9) COMP-3.
01 SUB-2 PIC S9(9) COMP-3.
01 TBL.
05 TBL-ENTRY-LVL-1 OCCURS 100000 TIMES
INDEXED BY TBL-1-INDEX.
10 TBL-ENTRY-LVL-2 OCCURS 10 TIMES
INDEXED BY TBL-2-INDEX.
15 TBL-TEXT-1 PIC X.
15 TBL-CHAR-1 PIC X.
PROCEDURE DIVISION.
PERFORM 050 TIMES
PERFORM VARYING SUB-1 FROM 1 BY 1
UNTIL SUB-1 > 100000
PERFORM VARYING SUB-2 FROM 1 BY 1
UNTIL SUB-2 > 10
MOVE SPACES TO TBL-TEXT-1 (SUB-1, SUB-2)
MOVE 'A' TO TBL-CHAR-1 (SUB-1, SUB-2)
END-PERFORM
END-PERFORM
END-PERFORM.
GOBACK.
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST003.
AUTHOR. CHUCK HAATVEDT
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SUB-1 PIC 9(9).
01 SUB-2 PIC 9(9).
01 TBL.
05 TBL-ENTRY-LVL-1 OCCURS 100000 TIMES
INDEXED BY TBL-1-INDEX.
10 TBL-ENTRY-LVL-2 OCCURS 10 TIMES
INDEXED BY TBL-2-INDEX.
15 TBL-TEXT-1 PIC X.
15 TBL-CHAR-1 PIC X.
PROCEDURE DIVISION.
PERFORM 050 TIMES
PERFORM VARYING SUB-1 FROM 1 BY 1
UNTIL SUB-1 > 100000
PERFORM VARYING SUB-2 FROM 1 BY 1
UNTIL SUB-2 > 10
MOVE SPACES TO TBL-TEXT-1 (SUB-1, SUB-2)
MOVE 'A' TO TBL-CHAR-1 (SUB-1, SUB-2)
END-PERFORM
END-PERFORM
END-PERFORM.
GOBACK.
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST005.
AUTHOR. CHUCK HAATVEDT
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MAX-1 PIC S9(9).
01 MAX-2 PIC S9(9).
01 WS-1 PIC 9 VALUE 1.
01 TBL.
05 TBL-ENTRY-LVL-1 OCCURS 100000 TIMES
INDEXED BY TBL-1-INDEX.
10 TBL-ENTRY-LVL-2 OCCURS 10 TIMES
INDEXED BY TBL-2-INDEX.
15 TBL-TEXT-1 PIC X.
15 TBL-CHAR-1 PIC X.
PROCEDURE DIVISION.
MOVE +100000 TO MAX-1.
MOVE +10 TO MAX-2.
PERFORM 050 TIMES
PERFORM VARYING TBL-1-INDEX FROM WS-1 BY WS-1
UNTIL TBL-1-INDEX > MAX-1
PERFORM VARYING TBL-2-INDEX FROM WS-1 BY WS-1
UNTIL TBL-2-INDEX > MAX-2
MOVE SPACES
TO TBL-TEXT-1 (TBL-1-INDEX, TBL-2-INDEX)
MOVE 'A'
TO TBL-CHAR-1 (TBL-1-INDEX, TBL-2-INDEX)
END-PERFORM
END-PERFORM
END-PERFORM.
GOBACK.
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST009.
AUTHOR. CHUCK HAATVEDT
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MAX-1 PIC S9(9) COMP.
01 MAX-2 PIC S9(9) COMP.
01 SVIDX-SAVE-INDEXES.
05 SVIDX-TBL-1-INDEX USAGE INDEX.
05 SVIDX-TBL-2-INDEX USAGE INDEX.
01 TBL.
05 TBL-ENTRY-LVL-1 OCCURS 100000 TIMES
INDEXED BY TBL-1-INDEX
TBL-1-INDEX-MAX.
10 TBL-ENTRY-LVL-2 OCCURS 10 TIMES
INDEXED BY TBL-2-INDEX
TBL-2-INDEX-MAX.
15 TBL-TEXT-1 PIC X.
15 TBL-CHAR-1 PIC X.
PROCEDURE DIVISION.
MOVE +100000 TO MAX-1.
MOVE +10 TO MAX-2.
SET TBL-1-INDEX TO MAX-1.
SET SVIDX-TBL-1-INDEX TO TBL-1-INDEX.
SET TBL-2-INDEX TO MAX-2.
SET SVIDX-TBL-2-INDEX TO TBL-2-INDEX.
PERFORM 050 TIMES
SET TBL-1-INDEX TO +1
PERFORM WITH TEST BEFORE
UNTIL TBL-1-INDEX > SVIDX-TBL-1-INDEX
SET TBL-2-INDEX TO +1
PERFORM WITH TEST BEFORE
UNTIL TBL-2-INDEX > SVIDX-TBL-2-INDEX
MOVE SPACES
TO TBL-TEXT-1 (TBL-1-INDEX, TBL-2-INDEX)
MOVE 'A'
TO TBL-CHAR-1 (TBL-1-INDEX, TBL-2-INDEX)
SET TBL-2-INDEX UP BY +1
END-PERFORM
SET TBL-1-INDEX UP BY +1
END-PERFORM
END-PERFORM.
GOBACK.