IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Subscript vs Index


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Keanehelp

New User


Joined: 27 May 2008
Posts: 71
Location: USA, CA.

PostPosted: Thu May 31, 2012 4:16 pm
Reply with quote

Hi,

I have to use an cobol array with only 7 occurances.
Can anyone suggest what would be better -- To use subscript or to use index?

I know that index is faster than subscript but with such a low number of occurances would it matter??? Also I think using Index will increase overhead. Please suggest.

Thanks
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu May 31, 2012 4:28 pm
Reply with quote

From the Enterprise COBOL Programming Guide manual:
Quote:
8.1.3 Handling tables efficiently




You can use several techniques to improve the efficiency of table-handling operations, and to influence the optimizer. The return for your efforts can be significant, particularly when table-handling operations are a major part of an application.


The following two guidelines affect your choice of how to refer to table elements:
Use indexing rather than subscripting. Although the compiler can eliminate duplicate indexes and subscripts, the original reference to a table element is more efficient with indexes (even if the subscripts were BINARY). The value of an index has the element size factored into it, whereas the value of a subscript must be multiplied by the element size when the subscript is used. The index already contains the displacement from the start of the table, and this value does not have to be calculated at run time. However, subscripting might be easier to understand and maintain.
Use relative indexing. Relative index references (that is, references in which an unsigned numeric literal is added to or subtracted from the index-name) are executed at least as fast as direct index references, and sometimes faster. There is no merit in keeping alternative indexes with the offset factored in.

However, for a table of 7 occurrences, the true answer is: you've already wasted more time thinking about the question than could EVER be saved by the program, no matter if it runs hourly for the next 50 years.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu May 31, 2012 4:42 pm
Reply with quote

the idea of indexing/subscripting is to allow for loops, thus saving on repetitive code.

since any use of 'indexing' involves a compare (does this occurance fit)
and a if not, a 'bump' of the index and another compare.

true, you could be just adding or subtracting or plain extracting,
but you have a loop where the 'bump' of the 'index' is required.

with a table with only 7 occurances,
absolute indexing (literal number)
would only entail 7 compares without the bumping,
you would save the runtime requirement to calculate the address (subscript + 1, or set up/down index by n)
since the compiler would have calculated the address.

Perform varying index/subscript from 1 by 1 until
involves the run time calculation,
whereas
Code:

EVALUATE TRUE
    WHEN ITEM(1) = COMPARE
         .....
    WHEN ITEM(2) = COMPARE
         .....
    WHEN ITEM(3) = COMPARE
         .....
    WHEN ITEM(4) = COMPARE
         .....
    WHEN ITEM(5) = COMPARE
         .....
    WHEN ITEM(6) = COMPARE
         .....
    WHEN ITEM(7) = COMPARE
         .....
    OTHERWISE
         .....
END-EVALUATE


would actually run faster, because there is no address calculation.

that said,
as Robert indicated,
with 7 occurances, and todays processor speeds,
you are wasting time even talking about the difference between indexing vs subscripting.

Another philosophical discussion posed by someone who does not understand the subject.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu May 31, 2012 6:40 pm
Reply with quote

Quote from Robert -

Quote:
However, for a table of 7 occurrences, the true answer is: you've already wasted more time thinking about the question than could EVER be saved by the program, no matter if it runs hourly for the next 50 years.

Couldn't have said it any better icon_lol.gif icon_lol.gif icon_lol.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu May 31, 2012 7:26 pm
Reply with quote

Hello,

Quote:
I know that index is faster than subscript but with such a low number of occurances would it matter??? Also I think using Index will increase overhead. Please suggest.

Suggest you set up a few little test modules (one for each approach you want to measure) that do the same "loop"/evaluate/etc several million times and look at the resources required. If you only do 100 or so loops, the difference might not be a good representation of the resource usage - high volume is needed . . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Cobol file using index COBOL Programming 2
No new posts Finding faulty logic Subscript out of... COBOL Programming 5
No new posts DL/I status code AK for GU call using... IMS DB/DC 1
No new posts Add column to existing records using ... JCL & VSAM 2
No new posts choice of clustering index DB2 3
Search our Forums:

Back to Top