View previous topic :: View next topic
|
Author |
Message |
sri_mf
Active User
Joined: 31 Aug 2006 Posts: 218 Location: India
|
|
|
|
Hi,
I am using a Array which is used to load the data sequentially,process it and write into on Output File.
Array is declared like this.
10 WS-TEMP-ARRAY OCCURS 10 TIMES INDEXED BY W-INDX.
15 WS-TEMP-YR PIC X(02).
15 WS-TEMP-NO PIC X(20).
For my Case as i m not searching the array ,just loading the Array and processing it sequentially. Will Index is advantageous over Suscript ? If so what are the reasons for that? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
using a subscript requires the occurance number be converted to an offset.
SETting the INDEX up by 1 increases the offset, not the occurance, therefore no conversion is necessary.
and it does not matter that you are not searching the table, you are addressing each occurance.
It is all in the programmer guide, top of page. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
I've always heard that IBM's claim is INDEX is faster than subscripts. However, for a 10-element table that is not searched, I doubt it really matters whether INDEX or subscript is used. |
|
Back to top |
|
|
sri_mf
Active User
Joined: 31 Aug 2006 Posts: 218 Location: India
|
|
|
|
Robert Sample wrote: |
However, for a 10-element table that is not searched, I doubt it really matters whether INDEX or subscript is used. |
For this Scenario will INDEX is preffered or not. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The Programmer's Guide doesn't specify a lower limit for efficiency, but I doubt you'd be able to easily measure the CPU time difference with only 10 table entries:
Quote: |
8.1.3 Handling tables efficiently
Pay close attention to table-handling operations, particularly when they are a major part of an application. Several techniques can improve the efficiency of these operations and can also influence the optimizer. The return for your efforts can be significant.
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 than with subscripts, even if the subscripts are 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 as fast as direct index references and sometimes faster. There is no merit in keeping alternative indexes with the offset factored in. |
|
|
Back to top |
|
|
sri_mf
Active User
Joined: 31 Aug 2006 Posts: 218 Location: India
|
|
|
|
Thanks Robert.But will the Usage of Index for this Scenario is disadvantagable when compared to subscript or for this scenario there will not be much diff if we use any of these(Index/Subscript) |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
IBM's manual statement I quoted earlier is clear. INDEX is always more efficient than subscripts, period. What I am saying is that for the table you have defined, the "more efficient" isn't going to be worth worrying about; probably a few nanoseconds or microseconds. Leave it indexed and move on to more important issues. |
|
Back to top |
|
|
sri_mf
Active User
Joined: 31 Aug 2006 Posts: 218 Location: India
|
|
|
|
Robert Sample wrote: |
IBM's manual statement I quoted earlier is clear. INDEX is always more efficient than subscripts, period. What I am saying is that for the table you have defined, the "more efficient" isn't going to be worth worrying about; probably a few nanoseconds or microseconds. Leave it indexed and move on to more important issues. |
Thanks Robert |
|
Back to top |
|
|
|