Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: "Rick Smith" <ricksmith@xxxxxxx>
- Date: Thu, 21 Jul 2005 01:54:03 -0400
"Pete Dashwood" <dashwood@xxxxxxxxxxxxxx> wrote in message
news:3k86utFl4gssU1@xxxxxxxxxxxxxxxxx
>
> "Clark Morris" <cfmtech@xxxxxxxx> wrote in message
> news:e1atd11fi2cshuqsgg11l78qp1n840102p@xxxxxxxxxx
> > On Tue, 19 Jul 2005 11:02:50 +1200, "Pete Dashwood"
> > <dashwood@xxxxxxxxxxxxxx> wrote:
> >
> >>
> <snip>>>
> >>2. The less code that is generated, the faster it will run.
> >
> > Not necessarily.
>
> Yes, necessarily. :-) Three factors affect online performance; two of
them
> are load time and capture time. The smaller and tighter a module is, the
> quicker it loads and it will be likely to require less capture time.
>
> Capture time for a process will be improved if there is less code for the
> process to execute (as long as it provides the same functionality, of
> course.)
>
> Adding code cannot possibly make it execute any faster than it is required
> to. And if everything else is equal, the faster load time of a smaller
> module makes overall execution quicker. If a small module is being paged
in
> and out continually, as opposed to a large resident piece of code, then
the
> overall execution of the small module functionality may be longer, but
that
> implies that the large piece of code is doing more (otherwise, why is it
so
> large?), so the comparison is between apples and oranges
>
> Given identical functionality and identical residence, the smaller the
code
> is, the quicker it will execute. Invariably.
Perhaps, Mr Dashwood, you had some additional restrictions
in mind; but there are cases where larger code, with 'identical
functionality', will execute faster.
The following program has two procedures to determine the
length of text (a string). The procedures have 'identical functionality',
in that they each accept a 32 character item and return its length
(the position of the last non-space character). They also function
identically by examining the 32 character item, in reverse, one
character at a time. Yet the larger procedure outperforms the smaller.
Test program
--------
program-id. unroll.
data division.
working-storage section.
1 str pic x(32) value space.
1 strlen-1 comp-5 pic 9(4) value 0.
1 strlen-2 comp-5 pic 9(4) value 0.
1 time-1.
2 time-1-hour pic 99.
2 time-1-minute pic 99.
2 time-1-second pic 99v99.
1 time-2.
2 time-2-hour pic 99.
2 time-2-minute pic 99.
2 time-2-second pic 99v99.
1 time-3.
2 time-3-hour pic 99.
2 time-3-minute pic 99.
2 time-3-second pic 99v99.
1 elapsed-time pic 9(7)v99.
1 elapsed-time-display pic z(6)9.99.
procedure division.
mainline section.
move spaces to str
perform time-test
move 'a' to str (16:1)
perform time-test
move 'a' to str (32:1)
perform time-test
stop run
.
time-test section.
accept time-1 from time
perform loop 100000000 times
accept time-2 from time
perform unrolled-loop 100000000 times
accept time-3 from time
display time-1
if time-1 > time-2
move 86400 to elapsed-time
else
move 0 to elapsed-time
end-if
compute elapsed-time = elapsed-time
+ (time-2-hour - time-1-hour) * 3600
+ (time-2-minute - time-1-minute) * 60
+ (time-2-second - time-1-second)
move elapsed-time to elapsed-time-display
display time-2 space elapsed-time-display
space strlen-1
if time-2 > time-3
move 86400 to elapsed-time
else
move 0 to elapsed-time
end-if
compute elapsed-time = elapsed-time
+ (time-3-hour - time-2-hour) * 3600
+ (time-3-minute - time-2-minute) * 60
+ (time-3-second - time-2-second)
move elapsed-time to elapsed-time-display
display time-3 space elapsed-time-display
space strlen-2
.
loop section.
perform varying strlen-1 from 32 by -1
until strlen-1 = 0
if space not = str (strlen-1:1)
exit perform
end-if
end-perform
.
unrolled-loop section.
evaluate space
when not = str (32:1) move 32 to strlen-2
when not = str (31:1) move 31 to strlen-2
when not = str (30:1) move 30 to strlen-2
when not = str (29:1) move 29 to strlen-2
when not = str (28:1) move 28 to strlen-2
when not = str (27:1) move 27 to strlen-2
when not = str (26:1) move 26 to strlen-2
when not = str (25:1) move 25 to strlen-2
when not = str (24:1) move 24 to strlen-2
when not = str (23:1) move 23 to strlen-2
when not = str (22:1) move 22 to strlen-2
when not = str (21:1) move 21 to strlen-2
when not = str (20:1) move 20 to strlen-2
when not = str (19:1) move 19 to strlen-2
when not = str (18:1) move 18 to strlen-2
when not = str (17:1) move 17 to strlen-2
when not = str (16:1) move 16 to strlen-2
when not = str (15:1) move 15 to strlen-2
when not = str (14:1) move 14 to strlen-2
when not = str (13:1) move 13 to strlen-2
when not = str (12:1) move 12 to strlen-2
when not = str (11:1) move 11 to strlen-2
when not = str (10:1) move 10 to strlen-2
when not = str (9:1) move 9 to strlen-2
when not = str (8:1) move 8 to strlen-2
when not = str (7:1) move 7 to strlen-2
when not = str (6:1) move 6 to strlen-2
when not = str (5:1) move 5 to strlen-2
when not = str (4:1) move 4 to strlen-2
when not = str (3:1) move 3 to strlen-2
when not = str (2:1) move 2 to strlen-2
when not = str (1:1) move 1 to strlen-2
when other move 0 to strlen-2
end-evaluate
.
end program unroll.
-------
Test results
--------
00585676
00591950 22.74 00000
00592449 4.99 00000
00592449
00593828 13.79 00016
00594119 2.91 00016
00594119
00594229 1.10 00032
00594328 0.99 00032
--------
.
- Follow-Ups:
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Joe Zitzelberger
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Pete Dashwood
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- References:
- Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Oliver Wong
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Oliver Wong
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: docdwarf
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Chuck Stevens
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: docdwarf
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Oliver Wong
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Pete Dashwood
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Howard Brazee
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Pete Dashwood
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Michael Mattias
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Pete Dashwood
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Howard Brazee
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Pete Dashwood
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Clark Morris
- Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- From: Pete Dashwood
- Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- Prev by Date: Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- Next by Date: Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- Previous by thread: Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- Next by thread: Re: Is it always possible to write a COBOL program using only 1 sentence per paragraph?
- Index(es):
Relevant Pages
|