Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Subscript vs Index

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Keanehelp

New User


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

PostPosted: Thu May 31, 2012 4:16 pm    Post subject: Subscript vs Index
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: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Thu May 31, 2012 4:28 pm    Post subject:
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: 6967
Location: porcelain throne

PostPosted: Thu May 31, 2012 4:42 pm    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu May 31, 2012 6:40 pm    Post subject: Reply to: Subscript vs Index
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

Site Director


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

PostPosted: Thu May 31, 2012 7:26 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts setting new limit Key values for inde... srilata83 DB2 1 Fri Feb 10, 2017 9:24 pm
No new posts Order BY AND Index Nileshkul DB2 2 Sat Dec 31, 2016 6:33 pm
No new posts Several errors during building altern... Andi1982 JCL & VSAM 11 Wed Jul 06, 2016 7:39 pm
No new posts Drop building Alternate Index for a p... bhavin.mehta JCL & VSAM 6 Mon Jul 04, 2016 3:47 pm
No new posts VSAM Alternate Index in CICS jacobdng CICS 2 Fri May 06, 2016 1:41 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us