Re: Cobol Myth Busters



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?
.



Relevant Pages

  • Cobol Myth Busters
    ... Use simple two-operand arithmetic statements wherever possible. ... ON SIZE ERROR phrase is used. ... access to tables of fixed size, and so should be avoided where high performance is needed. ... 05 depending-element occurs 1 to 4096 depending on binary-number. ...
    (comp.lang.cobol)
  • Re: Order by not working
    ... Depending on which link I click on it's either ... altering as I've added a line to print the query to the screen to make sure ... All I can say is on one server the data is displayed ... Where on the other server where ORDER BY 'count' could display the order in ...
    (comp.lang.php)
  • Re: A list box that changes what HTML is displayed.
    ... I would like to be able to have an HTML form where there is a list ... And the fact that you're even asking shows that you don't really understand how PHP works. ... If you only want to, let's say, display different invoice options depending on the answer to "Personal / Enterprise", you can load everything and use JavaScript to change the "display" CSS attribute. ...
    (comp.lang.php)
  • Re: How do I create a subform programmatically?
    ... the appropriate records to display in each case. ... 'Search' screen (with the 3 combos) be available and visible throughout the ... >>I need to create a sub form in code - depending on data displayed in my main ... > What would be the purpose of this new subform? ...
    (microsoft.public.access.formscoding)
  • Oddities of Tkinter
    ... I am building a tkinter program. ... from an incoming interface, and depending on the data, will display a ...
    (comp.lang.python)