HP3000-L Archives

June 2004, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Johan Harmsen <[log in to unmask]>
Reply To:
Johan Harmsen <[log in to unmask]>
Date:
Fri, 11 Jun 2004 17:44:22 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (129 lines)
Hi,

From my, almost forgotten, Cobol years I remember that calculations
using non COMP fields was/is evil, because of all conversions from
ASCII to Binary and reverse that take place.

The biggest performance gain for the program however is
a slight modification of the algorithm, because it is only necessary
to check the divisions until you reach the square root of the
potential prime number in stead of half of it, as in the program.

Johan


----- Original Message -----
From: "Mike Hornsby" <[log in to unmask]>
To: <[log in to unmask]>
Sent: Friday, 11 June, 2004 16:40
Subject: [HP3000-L] Friday COBOL Performance Trivia:


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?


Mike Hornsby Co-founder/Chief Technical Officer
Beechglen Development Inc. (beechglen.com)
513-922-0509 [log in to unmask]


 00014          001000 IDENTIFICATION DIVISION.
 00015          001100 PROGRAM-ID. PRIME.
 00016          001200 DATA DIVISION.
 00017          001300 WORKING-STORAGE SECTION.
 00018          001400 01 PRIME-FLAG     PIC X .
 00019          001500 01 CALC-NO        PIC 9(6) VALUE ZERO.
 00020          001600 01 DIV-NO         PIC 9(6) VALUE ZERO.
 00021          001700 01 R              PIC 9(9) VALUE ZERO.
 00022          001800 01 N              PIC 9(9) VALUE ZERO.
 00023          001900 01 PRIME-COUNT    PIC 9(5) VALUE 2.
 00024          002000 01 RUN-TIME       PIC 9(9) COMP.
 00025          002100
 00026          002200 PROCEDURE DIVISION.
 00027          002300 000-MAIN.
 00028          002400   PERFORM 100-CHECK-NUM THRU 100-EXIT
 00029          002500     VARYING CALC-NO FROM 3 BY 2
 00030          002600     UNTIL CALC-NO > 10000.
 00031          002700
 00032          002800   DISPLAY 'PRIMES= ' PRIME-COUNT.
 00033          002900     CALL INTRINSIC "PROCTIME" GIVING RUN-TIME.
 00034          003000     DISPLAY 'TOTAL CPU MSECS=' RUN-TIME.
 00035          003100   STOP RUN.
 00036          003200
 00037          003300 000-EXIT.
 00038          003400
 00039          003500 100-CHECK-NUM.
 00040          003600      MOVE "Y" TO PRIME-FLAG
 00041          003700      PERFORM 110-CALC-NUM THRU 110-EXIT
 00042          003800       VARYING DIV-NO FROM 3 BY 1
 00043          003900       UNTIL (DIV-NO > ((CALC-NO + 1) / 2)) OR
 00044          004000       PRIME-FLAG = "N".
 00045          004100       IF PRIME-FLAG = "Y" THEN
 00046          004200          ADD +1 TO PRIME-COUNT.
 00047          004300 100-EXIT. EXIT.
 00048          004400
 00049          004500 110-CALC-NUM.
 00050          004600        DIVIDE CALC-NO BY DIV-NO GIVING N REMAINDER R.
 00051          004700        IF R = 0 THEN MOVE 'N' TO PRIME-FLAG.
 00052          004800 110-EXIT. EXIT.
...
PRIMES= 01230
TOTAL CPU MSECS=000028051


 00014          001000$CONTROL OPTIMIZE=1,SYNC32,POST85
 00015          001100 IDENTIFICATION DIVISION.
 00016          001200 PROGRAM-ID. PRIME.
 00017          001300 DATA DIVISION.
 00018          001400 WORKING-STORAGE SECTION.
 00019          001500 01 PRIME-FLAG     PIC X .
 00020          001600 01 CALC-NO        PIC 9(6) COMP VALUE ZERO.
 00021          001700 01 DIV-NO         PIC 9(6) COMP VALUE ZERO.
 00022          001800 01 R              PIC 9(9) COMP VALUE ZERO.
 00023          001900 01 N              PIC 9(9) COMP VALUE ZERO.
 00024          002000 01 PRIME-COUNT    PIC 9(5) COMP VALUE 2.
 00025          002100 01 RUN-TIME       PIC 9(9) COMP.
 00026          002200
 00027          002300 PROCEDURE DIVISION.
 00028          002400 000-MAIN.
 00029          002500   PERFORM 100-CHECK-NUM THRU 100-EXIT
 00030          002600     VARYING CALC-NO FROM 3 BY 2
 00031          002700     UNTIL CALC-NO > 10000.
 00032          002800
 00033          002900   DISPLAY 'PRIMES= ' PRIME-COUNT.
 00034          003000     CALL INTRINSIC "PROCTIME" GIVING RUN-TIME.
 00035          003100     DISPLAY 'TOTAL CPU MSECS=' RUN-TIME.
 00036          003200   STOP RUN.
 00037          003300
 00038          003400 000-EXIT.
 00039          003500
 00040          003600 100-CHECK-NUM.
 00041          003700      MOVE "Y" TO PRIME-FLAG
 00042          003800      PERFORM 110-CALC-NUM THRU 110-EXIT
 00043          003900       VARYING DIV-NO FROM 3 BY 1
 00044          004000       UNTIL (DIV-NO > ((CALC-NO + 1) / 2)) OR
 00045          004100       PRIME-FLAG = "N".
 00046          004200       IF PRIME-FLAG = "Y" THEN
 00047          004300          ADD +1 TO PRIME-COUNT.
 00048          004400 100-EXIT. EXIT.
 00049          004500
 00050          004600 110-CALC-NUM.
 00051          004700        COMPUTE R = FUNCTION REM(CALC-NO DIV-NO).
 00052          004800        IF R = 0 THEN MOVE 'N' TO PRIME-FLAG.
 00053          004900 110-EXIT. EXIT.
...
PRIMES= 01230
TOTAL CPU MSECS=000004654



* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2