Microsoft KB Archive/47661

From BetaArchive Wiki

COBOL 3.00 Program Example for Timing or Benchmark Testing

PSS ID Number: Q47661 Article last modified on 08-07-1989

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: This article gives a code example for benchmark testing the speed of COBOL Version 3.00 or 3.00a statements. You can modify this program to test the timing of any desired COBOL statements or programs.

More Information: The following code example shows how to ACCEPT a data item from TIME before and after a test to determine the time required for the test. This code can be modified to perform a general timing test for most features of the COBOL language. This particular program compares two different forms of the DISPLAY statement to determine which is faster. Any routine or feature of the language could be substituted in the PERFORM. The results of the test could be used to write more efficient code. This information applies to Microsoft COBOL 3.00 and 3.00a for MS-DOS and MS OS/2. Timing results differ between MS-DOS and MS OS/2 and also differ on different computers depending upon the chip speed and other hardware-related factors.

Code Example

  * Compile line:
  *    COBOL timetest.cob;
  * Link line:
  *    LINK timetest adis adisinit adiskey;
  $SET ANS85 ERRQ
   DATA DIVISION.
   WORKING-STORAGE SECTION.
  * THIS IS ACCEPTED FROM TIME.
   01 START-TIME-REC.
     05 ST-HOURS      PIC 99.
     05 ST-MINUTES    PIC 99.
     05 ST-SECONDS    PIC 99.
     05 ST-HUNDREDTHS PIC 99.
  * THIS IS ACCEPTED FROM TIME.
   01 STOP-TIME-REC.
     05 SP-HOURS      PIC 99.
     05 SP-MINUTES    PIC 99.
     05 SP-SECONDS    PIC 99.
     05 SP-HUNDREDTHS PIC 99.
  * THE TIMES ARE STORED AS HUNDREDTHS OF SECONDS.
   01 START-TIME PIC 9(7).
   01 STOP-TIME  PIC 9(7).
   01 ELAPSED-TIME.
  * STORED AS HUNDREDTHS OF SECONDS.
      05 ELAPSED-TIME-VAR     PIC 9(7).
  * BREAK THIS VALUE INTO SECONDS AND HUNDREDTHS
  * SO THAT IT CAN BE DISPLAYED.
      05 ELAPSED-TIME-BREAKDOWN REDEFINES ELAPSED-TIME-VAR.
        10 ELAPSED-SECONDS    PIC 9(5).
        10 ELAPSED-HUNDREDTHS PIC 9(2).
  * USED TO DISPLAY THE FINAL RESULT OF THE TEST.
   01 DISPLAY-TIME.
     05 TOTAL-SECONDS PIC 9(5).
     05 FILLER PIC X VALUE ".".
     05 TOTAL-HUNDREDTHS PIC 9(2).
   SCREEN SECTION.
   01 SCREEN-1.
    05 HELLO LINE 1 COL 15 VALUE "HELLO"
           FOREGROUND-COLOR 3 BACKGROUND-COLOR 5.
   01 SCREEN-2.
    05 HELLO LINE 2 COL 15 VALUE "WORLD"
         FOREGROUND-COLOR 7 BACKGROUND-COLOR 1.
   PROCEDURE DIVISION.
   MAIN.
  * FIRST TEST.
      ACCEPT START-TIME-REC FROM TIME.
      PERFORM 1000 TIMES
          DISPLAY SCREEN-1
          DISPLAY SCREEN-2
      END-PERFORM.
      ACCEPT STOP-TIME-REC FROM TIME.
      PERFORM COMPUTE-TIME-ELAPSED.
      DISPLAY "SECONDS FOR MULTIPLE DISPLAYS: "
                          AT 1010 DISPLAY-TIME.
  * SECOND TEST.
      ACCEPT START-TIME-REC FROM TIME.
      PERFORM 1000 TIMES
          DISPLAY SCREEN-1, SCREEN-2
      END-PERFORM.
      ACCEPT STOP-TIME-REC FROM TIME.
      PERFORM COMPUTE-TIME-ELAPSED.
      DISPLAY
       "SECONDS FOR ONE DISPLAY STATEMENT (MULTIPLE SCREENS): "
        AT 1110 DISPLAY-TIME.
      STOP RUN.
   COMPUTE-TIME-ELAPSED.
  * CONVERT THE STARTING AT STOPPING TIMES TO HUNDREDTHS OF
  * SECONDS.
      COMPUTE START-TIME
         = (ST-HOURS * 360000) + (ST-MINUTES * 6000)
           + (ST-SECONDS * 100) + ST-HUNDREDTHS.
      COMPUTE STOP-TIME
         = (SP-HOURS * 360000) + (SP-MINUTES * 6000)
           + (SP-SECONDS * 100) + SP-HUNDREDTHS.
  * COMPUTE THE TIME ELAPSED.
      COMPUTE ELAPSED-TIME-VAR = STOP-TIME - START-TIME.
      MOVE ELAPSED-SECONDS TO TOTAL-SECONDS.
      MOVE ELAPSED-HUNDREDTHS TO TOTAL-HUNDREDTHS.

Copyright Microsoft Corporation 1989.