I tunnig a system in my jobs and it have a lot of arithmetics operations.
One people tell me to change the command COMPUTE for ADD, DIVIDE, MULTIPLY and SUBTRACT, but I don't if is the really better .
What is more faster: COMPUTE or the other arithmetics statements.
Somebody can help me?
And the other side of the coin is -- why do you think it matters? Modern machines can run, literally, hundreds of millions of COBOL statements per minute of CPU time. So you'd have to be doing billions upon billions upon billions of arithmetic operations for any difference to be really noticeable. The code algorithms are going to make much more difference in your end results than picking the "faster" computational method.
Joined: 30 Nov 2010 Posts: 28 Location: Chennai, Tamilnadu,INDIA
Delago,
When you need to combine arithmetic operations, using the COMPUTE statement may be more efficient than writing a series of separate arithmetic statements. Because it allows you to combine arithmetic operations without the restrictions on receiving data items that the rules for the ADD, SUBTRACT, MULTIPLY, and DIVIDE statements impose.
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
Try to avoid (unless absolutely necessary) computations on doubleword-binary (an unfriendly format for COBOL), PIC 9(10) through PIC 9(18) COMP/COMP-4/BINARY.
Even if your compiler supports COMP-5, it is suggested to limit doubleword-binary computation usage.
In some cases of doubleword-binary computations, the compiler may very well resolve to calling a COBOL run-time routine, instead of resolving in-line.
FWIW, this is also true for COBOL exponentiation computations.
Bill
PS: I said to my Doctor "When I hit my hand with this hammer, it hurts". His reply "Then don't do that!". IMHO, this same idea applies to doubleword-binary usage in COBOL.
Calculate the exponent ahead of time and issue a straight multiply -
Code:
COMPUTE WS-RESULT = (WS-BASE * 128).
For small exponents, a loop multiply would suffice.
But, keep in mind that regardless of the data-type, which could also be packed-decimal, display-numeric, binary-halfword or binary-fullword, COBOL deals with exponentiation via a run-time routine.
Enterprise PL/I deals with 64-Bit (Doubleword) Arithmetic much better than COBOL as the PL/I compile folks utilize the more modern Assembler "Grande" instructions for in-line computations, such as "LG" (Load Grande), "AG" (Add Grande), CVDG ("Convert to Decimal Grande"), etc, which all use 64-Bit registers.
Although I haven't worked with it for nearly 30 years, PL/I has always been ahead of the curve when utilizing newer techniques. IMHO, a superior HLL to that of COBOL.
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
According to the latest Enterprise Cobol Performance Tuning Guide , floating-point is much faster than fixed point (up to 98%) when you are doing exponentiation. I have not verified this but it's interesting.