COMP OR COMP-3: WHICH IS FASTER?



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

COMP OR COMP-3: WHICH IS FASTER?

Postby utpalpal07 » Mon Feb 20, 2012 1:02 pm

WHICH IS FASTER?
COMP OR COMP-3?


Please explain in regarding the space content also....

regards
Utpal
utpalpal07
 
Posts: 43
Joined: Wed Feb 08, 2012 12:02 pm
Has thanked: 1 time
Been thanked: 0 time

Re: COMP OR COMP-3: WHICH IS FASTER?

 

Re: COMP OR COMP-3: WHICH IS FASTER?

Postby BillyBoyo » Mon Feb 20, 2012 1:10 pm

Faster at what? To type? Comp. Something else, let us know, please. If you define some samples in your Cobol program and look at the MAP output, you should get some clues about the sizes. Also, and you should have done so already, consult the manuals.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: COMP OR COMP-3: WHICH IS FASTER?

Postby enrico-sorichetti » Mon Feb 20, 2012 1:18 pm

unlikely it will make any difference unless You run a loop novemtrigintillion times :geek:
( why not run a little benchmark Yourself )

display the time
run an empty loop to find the loop overhead
display the time
run the real benchmark loop with the statement You want to benchmark
display the time
find out the NET total statement execution time
divide by the number of iterations
and Your curiosity will be satisfied
(or better... use the CPU time, it will be pretty invariant )

IBM does not publish timing data any more
if You are curious about IT archeology here is an historical reference
http://bitsavers.org/pdf/ibm/360/A22-68 ... Timing.pdf
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

These users thanked the author enrico-sorichetti for the post:
Aki88 (Wed Mar 26, 2014 12:04 pm)
enrico-sorichetti
Global moderator
 
Posts: 2644
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: COMP OR COMP-3: WHICH IS FASTER?

Postby Robert Sample » Mon Feb 20, 2012 3:35 pm

Asking which is faster is like asking "How high is up?" The answer is that it depends -- on how you are using the variables, for example. Furthermore, at a time when COBOL statements execute in the range of millions of lines of code per second of CPU time, just why do you think the answer matters at all? If one of them takes 4.0 nanoseconds and the other 4.05 nanoseconds per statement, what do you gain by knowing that?
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: COMP OR COMP-3: WHICH IS FASTER?

Postby Monitor » Mon Feb 20, 2012 5:56 pm

Comp-3 = Packed-Decimal is faster, because the z/Architecture, and also previous architectureres beginning with S/360, has built in instructions to directly manipulate Packed-Decimal data, e.g AP (Add packed). For other numeric formats, the compiler has to generate code to manipulate the numeric variable in different ways.

Have a look at this sample program:

 000010  cbl list                                           
000100  Identification Division.                           
000200  Program-Id. PACKED.                                 
000210  Data Division.                                     
000300  Working-Storage Section.                           
000400  77 Ws-PackedS    Pic S9(07) Packed-Decimal Value 0.
000410  77 Ws-Packed     Pic  9(07) Packed-Decimal Value 0.
000500  77 Ws-BinaryS    Pic S9(07) Binary Value 0.         
000510  77 Ws-Binary     Pic  9(07) Binary Value 0.         
000600                                                     
000700  Procedure Division.                                 
000800      Add 1 to Ws-PackedS                             
000810      Add 1 to Ws-Packed                             
000900      Add 1 to Ws-BinaryS                             
000910      Add 1 to Ws-Binary                             
001000      GoBack                                         
001100      .                                               


This is the code that is generated by the compiler:

000011  *                                                                       
000011  ADD                                                                     
   000334  FA30 8000 A02E          AP    0(4,8),46(1,10)         WS-PACKEDS     
   00033A  F833 8000 8000          ZAP   0(4,8),0(4,8)           WS-PACKEDS     
000012  ADD                                                                     
   000340  D203 D100 8008          MVC   256(4,13),8(8)          TS2=0         
   000346  960F D103               OI    259(13),X'0F'           TS2=3         
   00034A  FA30 D100 A02E          AP    256(4,13),46(1,10)      TS2=0         
   000350  D203 8008 D100          MVC   8(4,8),256(13)          WS-PACKED     
   000356  960F 800B               OI    11(8),X'0F'             WS-PACKED+3   
000013  ADD                                                                     
   00035A  4830 A012               LH    3,18(0,10)              PGMLIT AT +10 
   00035E  5A30 8010               A     3,16(0,8)               WS-BINARYS     
   000362  1823                    LR    2,3                                   
   000364  8E20 0020               SRDA  2,32(0)                               
   000368  5D20 C000               D     2,0(0,12)               SYSLIT AT +0   
   00036C  5020 8010               ST    2,16(0,8)               WS-BINARYS     
000014  ADD                                                                     
   000370  4830 A012               LH    3,18(0,10)              PGMLIT AT +10 
   000374  5A30 8018               A     3,24(0,8)               WS-BINARY     
   000378  1823                    LR    2,3                                   
   00037A  8E20 0020               SRDA  2,32(0)                               
   00037E  5D20 C000               D     2,0(0,12)               SYSLIT AT +0   
   000382  5020 8018               ST    2,24(0,8)               WS-BINARY     
000015  GOBACK                                                                                                                               


Even if you are not an assembler specialist, you can easily tell that the the first add generates fewer HW-instructions to do the same task, not to say that fewer always is faster, it depends on the format of the instructions. Pls also observe that if you specify the numeric variable without a sign, there is more code.
The best choice is Packed-Decimal (COMP-3) and a Sign (S9).
Regarding space Packed-Decimal is more effective, as the data is stored as decimal data, one decimal digit in one half byte, as Binary uses one byte oer digit.
Monitor
 
Posts: 98
Joined: Wed Jan 18, 2012 8:59 pm
Has thanked: 0 time
Been thanked: 7 times

Re: COMP OR COMP-3: WHICH IS FASTER?

Postby BillyBoyo » Mon Feb 20, 2012 8:03 pm

Monitor, please review Robert Sample's answer. Even the information you are providing may not help TS at all if he is doing something else than you have shown.

Also consult enrico's interesting link. Even though AP and AH are one instruction each, I really do imagine if you look at the document one is considerably "faster" than the other.

What if TS wants to access a table using a subscript? You still recommend comp-3?

Would you also like to review your comments about the lengths/digits of comp fields?

The original question has no answer in itself. Even if details of particular use are included, any change at this level is unlikely to make anything noticeably "faster".
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: COMP OR COMP-3: WHICH IS FASTER?

Postby Monitor » Mon Feb 20, 2012 8:18 pm

Futhermore the Sign, for a Packed-Decimal numeric variable, is stored in the leftmost halfbyte. If you declare, e.g., Pic S9(06), this means 6 decimal digits, which require 6 halfbytes = 3 bytes, BUT the sign will need another halfbyte. Since you cant allocate half-bytes, this variable need 4 bytes, where one (1) half-byte will never be used. Better to declare Pic S9(07), which also requires 4 bytes, and you have another decimal digit available, making the maximum value 10 times higher. So, always declare an odd number of digits, to use the allocated storage.
Monitor
 
Posts: 98
Joined: Wed Jan 18, 2012 8:59 pm
Has thanked: 0 time
Been thanked: 7 times

Re: COMP OR COMP-3: WHICH IS FASTER?

Postby Monitor » Mon Feb 20, 2012 8:37 pm

Billy, sorry for the mistake on Binary (Comp). This is of course stored in binary format. My comment on size is valid for S9(xx) (Usage is Display), where every digit is a whole byte. My comment doesnt cover Subscripts and Indexes, where recommendation is Comp/Binary.
Monitor
 
Posts: 98
Joined: Wed Jan 18, 2012 8:59 pm
Has thanked: 0 time
Been thanked: 7 times

Re: COMP OR COMP-3: WHICH IS FASTER?

Postby BillyBoyo » Mon Feb 20, 2012 8:40 pm

OK, just try to slow down a bit, maybe. The sign for a packed-decimal, as I'm sure you know, is not in either the left-most or even a left half-byte. It is in the rightmost.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: COMP OR COMP-3: WHICH IS FASTER?

Postby Robert Sample » Mon Feb 20, 2012 8:41 pm

Monitor, the Enterprise COBOL Language Reference manual disagrees with your statement
Futhermore the Sign, for a Packed-Decimal numeric variable, is stored in the leftmost halfbyte.
where section 5.3.17.1 of the manual specifically states
PACKED-DECIMAL
Specified for internal decimal items. Such an item appears in storage in packed decimal format. There are two digits for each character position, except for the trailing character position, which is occupied by the low-order digit and the sign. Such an item can contain any of the digits 0 through 9, plus a sign, representing a value not exceeding 18 decimal digits.

The sign representation uses the same bit configuration as the 4-bit sign representation in zoned decimal fields. For details, see the Enterprise COBOL Programming Guide.
Now, YOU may consider the trailing byte to be the "leftmost halfbyte" but MOST people read left-to-right and hence would consider your statement to be the direct opposite of the actual sign location.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post