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