Home   [... Table of Contents]

Blast Off With BASIC



© 1991 Brian R. Page

Blast Off With BASIC



© 1991 Brian R. Page

Appendix C: Computer Speed

This program measures the speed of a personal computer running the BASIC interpreter. The output of the program is a number which may be used in a FOR-NEXT loop to keep the machine busy for exactly one second. Often, such a loop is useful when the execution of a program must be delayed for a certain amount of time. This technique was used in the ROCKET3 program to display the countdown for a rocket launch.

The duration is accurate only when the FOR statement is immediately followed by the NEXT statement. Obviously, if any additional statements are added to the loop, the amount of time will be increased.

10  REM *************************************************************
11  REM *  IPS                                                      *
20  REM *  This program will calculate a FOR-NEXT loop that takes   *
30  REM *  one second to run.                                       *
40  REM *************************************************************
50  BEGTIME!  = TIMER
60  FOR X% = 1 TO 29999
70  NEXT X%
80  ENDTIME!  = TIMER
90  ELAPSED% = ENDTIME! - BEGTIME!
100 PRINT "Elapsed time is " ELAPSED%
110 IPS% = X% \ ELAPSED%
120 PRINT "Number of times through the loop =" X%
130 PRINT "Instructions per second =" IPS%
140 END
Top

Appendix B: DOS Command Summar   [... TOC]   Appendix D: Reserved Words in BASIC