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
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.
Calculate the exponent ahead of time and issue a straight multiply -
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: 686 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.