> -----Original Message-----
> From: Mike Hornsby
>
> Below are two versions of the same COBOL Prime number program.
> The first version took 28,051 CPU Milliseconds, the final
> version took 4,654 Milliseconds.
> Friday's trivia question is: What changes resulted in the
> largest performance gains, and why?
Even before I looked, I figured one "difference" would be character-based PICs vs. "COMPUTATIONAL" -- without the "[usage] comp" clause on a PIC statement, "numeric" variables are actually stored as character sequences, and internally are prone to lots of conversions between text-and-binary representtions of the number.
BUT, since you asked "what resulted in the LARGEST gain", I take it you actually did "several" speed-enhancements -- while there may be some synergy, the only way to answer this would be to make "one change at a time" -- starting from the original:
* make the numeric variables COMP instead of DISPLAY
* use the FUNCTION REM(...) instead of DIVIDE REMAINDER
- and if FUNCTION REM... is faster, fold the test into the IF
statement and avoid storing the intermediate, i.e.,
IF FUNCTION REM(CALC-NO DIV-NO) = ZERO THEN...
- OR try a level-88 on variable R, AS IN
05 R PIC S9(9) COMP.
88 NOT-A-PRIME VALUE ZERO.
...
PERFORM ... UNTIL (DIV-NO > CALC-ROOT)
OR NOT-A-PRIME
* for that matter, instead of > CALC-NO + 1 / 2, your limit
should be the square root of calc-no
* and while you're at it, calculate the limit once instead
of every iteration (i.e., COMPUTE CALC-ROOT = FUNCTION SQRT(CALC-NO) )
then use as shown above
after you've tried each of these /STARTING FROM THE ORIGINAL EACH TIME/, try combinations of two techniques, etc.
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|