qb45advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
TIMER Function Programming Example
  QuickSCREEN      Details     Example      Contents      Index
──────────────────────────────────────────────────────────────────────────────
TIMER Function Programming Example
 
The following program searches for the prime numbers from 3 to 10,000
using a variation of the Sieve of Eratosthenes. The TIMER function
is used to time the program.
 
'*** Programming example for the TIMER function
'
DEFINT A-Z
CONST UNMARK = 0, MARKIT = NOT UNMARK
DIM Mark(10000)
CLS                     'Clear the screen
Start! = TIMER
Num = 0
FOR N = 3 TO 10000 STEP 2
   IF NOT Mark(N) THEN
      'PRINT N,   'To print the primes, remove the
                  'remark delimiter in front of the
                  'PRINT statement.
      Delta = 2*N
      FOR I = 3*N TO 10000 STEP Delta
         Mark(I) = MARKIT
      NEXT
      Num = Num + 1
   END IF
NEXT
Finish! = TIMER
PRINT
PRINT "Program took";Finish! - Start!;
PRINT "seconds to find the";Num;"primes"
END
 
Sample Output
 
Program took .1601563 seconds to find the 1228 primes