For Programmers: Free Programming Magazines  


Home > Archive > Cobol > July 2005 > Re: Is it always possible to write a COBOL program using only 1 sentence per paragrap









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Is it always possible to write a COBOL program using only 1 sentence per paragrap
Joe Zitzelberger

2005-07-25, 10:02 pm

In article <11due6mb9fhfac3@corp.supernews.com>,
"Rick Smith" <ricksmith@mfi.net> wrote:
> 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

<snip>
> 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
> --------



Interesting, but you seem to have intentionally handicapped the loop
version.

Had you written it like this:

"perform varying strlen-1 from length of str by -1"

Then you would have had a flexible routine that will work in pretty much
any case and could be reused frequently. This benefit would surely
outweigh the trivial speed gain you would receive from the unrolled-loop
version.

Consider also that an optimizing compiler is likely to unroll the loop
version for you if all of the necessary values are known at compile time.

It is likely that the unrolled version of the code will never recover in
runtime the amount of typing type the programmer spent writing it.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com