COBOL "non-myth" confirmed - Index and subscripts (MF on Windows)



I do not have a Unix or Linux environment to test this on, but I did create a
program to test subscripts vs indices with Micro Focus Net Express 5.0 (Warp 03)
on Windows. The following programs (one a driver to run the other two)
confirmed that the program using indices in THIS environment runs about 1/3
slower with subscripts than with indices. (I tried it with the STANDARD
"Binary" and then changed it to "Comp-5". The latter, non-portable version runs
a little faster and is listed below - but is still measurably slower than the
one with indices). I would be interested in results with other compilers and/or
environments. (Change COMP-5 to BINARY if required. Otherwise, I think it is
sully '85 Standard - with Intrinsic Functions - conforming).

(Hopefully "indentation" etc will stay OK. If not, let me know and I'll put the
source programs on the web for download.

Driver Program:

Identification Division.

Program-Id. IndSub.

Procedure Division.

Mainline.

Call "TstSub"

Call "TstInd"

Stop Run

.



* * * * * * * *

Test Indices



Identification Division.

Program-ID. TstInd.

Data Division.

Working-Storage Section.

01 Time-Flds.

05 Start-Time Pic X(08).

05 End-Time Pic X(08).

05 Temp-Time.

10 Pic X.

10 M-Dig2 Pic 9.

10 Pic X.

10 S-Dig2 Pic 9.

10 H-Dig1 Pic 9.

10 H-Dig2 Pic 9.

01 TabA.

05 Tabl1A occurs 10 Times

indexed by Ind1a.

10 T1A Pic X(03).

10 Tabl2A Occurs 10 Times

Indexed by Ind2a.

15 T2A Pic X(33).

15 Tabl3A Occurs 10 Times

Indexed by Ind3A.

20 T3a Pic X.

20 Tabl4A Occurs 10 times

Indexed by Ind4a.

25 T4A Pic X(11).

25 ElemA Pic X(300).

15 T2AA Pic X.

10 T1AA Pic X(5).

01 Tabb.

05 Tabl1b occurs 10 Times

indexed by Ind1b.

10 T1b Pic X(11).

10 Tabl2b Occurs 10 Times

Indexed by Ind2b.

15 T2b Pic X(22).

15 Tabl3b Occurs 10 Times

Indexed by Ind3b.

20 T3b Pic X(05).

20 Tabl4b Occurs 10 times

Indexed by Ind4b.

25 T4b Pic X(11).

25 Elemb Pic X(300).

15 T2bb Pic X(11).

10 T1bb Pic X(3).



Procedure Division.

Mainline.

Move Function Current-Date (9:8) to Start-Time

Perform Loop 500000 Times

Move Function Current-Date (9:8) to End-Time

Display " *** Testing Indices * * *"

Display "Start-Time:"

Start-Time (1:2) ":"

Start-Time (3:2) ":"

Start-Time (5:2) "."

Start-Time (7:2)

Display " End-Time:"

End-Time (1:2) ":"

End-Time (3:2) ":"

End-Time (5:2) "."

End-Time (7:2)

.

If-Called.

Exit Program

.

If-Main.

Stop Run

.

Loop.

Move Function Current-Date (11:6) to Temp-Time

Set Ind1a to M-Dig2

Set Ind2a to S-Dig2

Set Ind3a to H-Dig1

Set Ind4a to H-Dig2

Set Ind1A up by 1

Set Ind2a up by 1

Set Ind3a up by 1

Set Ind4a up by 1

Move High-Values to ElemA (Ind1a Ind2a Ind3a Ind4a)

Set Ind2b to M-Dig2

Set Ind4b to S-Dig2

Set Ind1b to H-Dig1

Set Ind3b to H-Dig2

Set Ind1b up by 1

Set Ind2b up by 1

Set Ind3b up by 1

Set Ind4b up by 1

Move ElemA (Ind1a Ind2a Ind3a Ind4a) to

ElemB (Ind1b Ind2b Ind3b Ind4b)

.

* * * * * * * *

Test Subscripts:



Identification Division.

Program-ID. TstSub.

Data Division.

Working-Storage Section.

01 Time-Flds.

05 Start-Time Pic X(08).

05 End-Time Pic X(08).

05 Temp-Time.

10 Pic X.

10 M-Dig2 Pic 9.

10 Pic X.

10 S-Dig2 Pic 9.

10 H-Dig1 Pic 9.

10 H-Dig2 Pic 9.

01 TabA.

05 Tabl1A occurs 10 Times

indexed by Ind1a.

10 T1A Pic X(03).

10 Tabl2A Occurs 10 Times

Indexed by Ind2a.

15 T2A Pic X(33).

15 Tabl3A Occurs 10 Times

Indexed by Ind3A.

20 T3a Pic X.

20 Tabl4A Occurs 10 times

Indexed by Ind4a.

25 T4A Pic X(11).

25 ElemA Pic X(300).

15 T2AA Pic X.

10 T1AA Pic X(5).

01 Tabb.

05 Tabl1b occurs 10 Times

indexed by Ind1b.

10 T1b Pic X(11).

10 Tabl2b Occurs 10 Times

Indexed by Ind2b.

15 T2b Pic X(22).

15 Tabl3b Occurs 10 Times

Indexed by Ind3b.

20 T3b Pic X(05).

20 Tabl4b Occurs 10 times

Indexed by Ind4b.

25 T4b Pic X(11).

25 Elemb Pic X(300).

15 T2bb Pic X(11).

10 T1bb Pic X(3).



01 Subs.

05 Sub1a Pic S9(04) Comp-5.

05 Sub2a Pic S9(04) Comp-5.

05 Sub3a Pic S9(04) Comp-5.

05 Sub4a Pic S9(04) Comp-5.

05 Sub1b Pic S9(04) Comp-5.

05 Sub2b Pic S9(04) Comp-5.

05 Sub3b Pic S9(04) Comp-5.

05 Sub4b Pic S9(04) Comp-5.



Procedure Division.

Mainline.

Move Function Current-Date (9:8) to Start-Time

Perform Loop 500000 Times

Move Function Current-Date (9:8) to End-Time

Display " * * * Testing Subscripts * * *"

Display "Start-Time:"

Start-Time (1:2) ":"

Start-Time (3:2) ":"

Start-Time (5:2) "."

Start-Time (7:2)

Display " End-Time:"

End-Time (1:2) ":"

End-Time (3:2) ":"

End-Time (5:2) "."

End-Time (7:2)

.

If-Called.

Exit Program

.

If-Main.

Stop Run

.

Loop.

Move Function Current-Date (11:6) to Temp-Time

Move M-Dig2 To Sub1a

Move S-Dig2 to Sub2a

Move H-Dig1 to Sub3a

Move H-Dig2 to Sub4a

Add 1 to Sub1a

Add 1 to Sub2a

Add 1 to Sub3a

Add 1 to Sub4a

Move High-Values to ElemA (Sub1a Sub2a Sub3a Sub4a)

Move M-Dig2 To Sub1b

Move S-Dig2 to Sub2b

Move H-Dig1 to Sub3b

Move H-Dig2 to Sub4b

Add 1 to Sub1b

Add 1 to Sub2b

Add 1 to Sub3b

Add 1 to Sub4b

Move ElemA (Sub1a Sub2a Sub3a Sub4a) to

ElemB (Sub1b Sub2b Sub3b Sub4b)

.




--
Bill Klein
wmklein <at> ix.netcom.com


.



Relevant Pages