TIMER Function
Action
Returns the number of seconds elapsed since midnight.
Syntax
TIMER
Remarks
The TIMER function can be used with the RANDOMIZE statement to generate a
random number. It also can be used to time programs or parts of programs.
See Also
Randomize
Example
The following example 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.
DEFINT A-Z
CONST UNMARK = 0, MARKIT = NOT UNMARK
DIM Mark(10000)
CLS ' Clear 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
Output
Program took .28125 seconds to find the 1228 primes.