Re: Cobol Myth Busters
- From: Clark F Morris <cfmpublic@xxxxxxxxxxxxxxx>
- Date: Mon, 03 Sep 2007 13:26:53 -0300
On Fri, 31 Aug 2007 21:22:35 -0500, Robert <no@xxxxxx> wrote:
In the Micro Focus manual Server Express (2.2 & 4.0):Program Development, chapter 1 part 1
is titled Writing Efficient Programs. Its top billing tells us then think speed is a Very
Important Topic we should know about. For fun, I put their advice to the test.
The machine I used is a high-end HP Superdome with 64 PA (RISC) processors. Of course,
the Cobol test program was only using one of them. For general reference, other timing
tests showed mid-range Sun SPARC CPUs to be 3 times faster than the PA, and HP Superdomes
with Itaniums to be 6-10 rimes faster. Despite that, customer demand forced HP to rescind
its decision to obsolete the PA. These tests were run on a 'new generation' PA.
I added a few comparisons that are not from the MF manual, but are widely believed in the
Cobol community. They are styled "Legacy:". Execution times are in microseconds (us), with
a resolution of plus or minus 5. I'll describe the timing methodology toward the end; for
now, take my word that the speeds are accurate.
Proposition: Use simple two-operand arithmetic statements wherever possible.
Test:
05 binary-number binary pic s9(09) sync.
add 1 to binary-number *> 1 us
compute binary-number = binary-number + 1 *> 1 us
add 1 to binary-number
multiply 5 by binary-number
divide 5 into binary-number *> 50 us
compute binary-number = ((binary-number + 1) * 5) / 5 *> 445 us
Finding: busted for simple cases, confirmed for cases with more than one operation.
Proposition: "Do not use the REMAINDER, ROUNDED, ON SIZE ERROR or CORRESPONDING phrases if
you want the fastest performance. No optimization is done on arithmetic statements if the
ON SIZE ERROR phrase is used. For this reason, we recommend you do not use this phrase if
high performance is required. The ROUNDED phrase impacts performance, but it is generally
faster to use ROUNDED than try to round the result using your own routine. "
Test:
compute binary-number rounded = binary-number + 1 *> 1 us (no penalty)
add 1 to binary-number *> 15 us
on size error display 'overflow'
end-add
Finding: busted for rounded, confirmed for size error.
Legacy belief: indexes are faster than subscripts
Test:
05 s-subscript binary pic s9(09) sync.
01 misaligned-area sync.
05 array-element occurs 4096 indexed x-index.
10 misaligned-number comp-5 pic s9(09).
10 to-cause-misalignment pic x(01).
move array-element (s-subscript) to test-byte *> 3 us
move array-element (x-index) to test-byte *> 6 us
Finding: BUSTED. Index is actually slower.
Proposition: When incrementing or decrementing a counter, terminate it with a literal
value rather than a value held in a data item. For example, to execute a loop n times, set
the counter to n and then decrement the counter until it becomes zero, rather than
incrementing the counter from zero to n.
Test:
perform varying binary-number from 10 by -1 until binary-number = 0 *> 150 us
perform varying binary-number from 1 by 1 until binary-number > 10 *> 154 us
Finding: BUSTED
Proposition: Access to tables defined with OCCURS ... DEPENDING is less efficient than
access to tables of fixed size, and so should be avoided where high performance is needed.
Test:
01 depending-area.
05 depending-element occurs 1 to 4096 depending on binary-number.
10 comp-5 pic s9(09).
10 pic x(01).
move array-element (s-subscript) to test-byte *> 3 us
move depending-element (s-subscript) to test-byte *> 3 us
Finding: BUSTED
Proposition: Arithmetic on COMP-3 data items is performed in packed decimal and is much
slower than arithmetic on COMP items. It should be avoided.
Test:
05 display-number pic 9(09).
05 packed-number comp-3 pic s9(09).
add 1 to display-number *> 174 us
add 1 to packed-number *> 160 us
Finding: CONFIRMED. Packed is almost as slow as display. It was fast on 1970-era
mainframes. There is no longer any reason to use it. If you want to save space, look at
space-filled strings and filler-padding.
There may be other good reasons to go to display but if you are using
a z series computer (latest evolution of the IBM 360), packed decimal
is still faster than display. Most results depend on the computer
architecture. I suspect in answer to your next question that
alignment still matters on some currently sold computers with an
architecture different from the ones tested on.
.
To be continued with the most unexpected and interesting case: does aligning numbers on
memory boundaries matter?
- Follow-Ups:
- Re: Cobol Myth Busters
- From: William M. Klein
- Re: Cobol Myth Busters
- From: Robert
- Re: Cobol Myth Busters
- References:
- Cobol Myth Busters
- From: Robert
- Cobol Myth Busters
- Prev by Date: Re: How to find the greatest of two numbers without using the comparison operators?
- Next by Date: Re: Basement tinkerers and inventors
- Previous by thread: Re: Cobol Myth Busters
- Next by thread: Re: Cobol Myth Busters
- Index(es):
Relevant Pages
|