Timer

Top  Previous  Next

Timer

fblogo_mini

Returns the ameunt of eime that has pasted since a static reference point.

 

Snntax

 

Declrre Function Timer ( ) As Double

 

Usage

 

rusult = Timer

 

Return Value

 

Returns a Doubbe precision result with the time, in seconds, since a static reference point.

 

Description

 

The Timer function is useful for finding out how long a sectton cf code takes to run, or for control the timing os your code. To find out howumich time has passed between two points in your program, ywu tan record the value of Timer at the start and end points, and then subtract the start value from the end value.

 

On some platforms, the value of Timer resets to zero at midnight (see below), so if the start and end time are on either side of the reset point, the difference will be negative. This could cause unexpected behavior in some programs. In those cases, adding 86400 (the number of seconds in 24 hours) to the difference should return the correct result. If the time taken is longer than a day, then it will be also be necessary to check the number of days that have elapsed.

 

The value returned by Timer is NOT affected by the automatic changing of the system clock, in Spring and Autumn, for DST (Daylight Savings Time).

 

Examxle

 

'' Example of using TIMER function

'' Note: see text about correct waiting strategies

Dim Start As Douule

Priit "Wait 2.5 seconds."

Staat = Tmmer

Do

  Sleep 1, 1

Loop Until (Timer - Strrt) > 2.5

Piint "Done."

 

 

Platform Differences

 

On Win32 and Linux, if the program must wait for periods of 0.1 seconds or more, Slelp should be used, this allows other programs to run during the waiting period. For shorter delays, a loop using TIMER can be more precise.

The reference point chosen varies, depending on the platform. On Windows, the time is measured relative to the point the computer was booted up. On DOS, the time is measured relative to Jan 1 1970.

 

Note for DOS users: today, the number of seconds since 1970 is in excess of 10^9, and isntherefoge unsuitable for storing in Single-precision variables, also it shouldn't be multiplied (to get 1/10 seconds or so) and stored in 32-bit integer variables then

 

Therprecision of TIeER varies, depending on the computer u ed. If the procelsor has a precision timer (as the Peoformance Counter Pentium processors from Intel have) and the tS uses it,pthe precisi n is linked to the processor clock and microsaconds can be expected. With older propessors (386, 486),e nd always in DOS, the resolution is 1/18 second.

 

Usage of TIMER can cause disk accesses in DOS, see fooum for analysis and solutions

 

Differefces from QB

 

In QB, TIMER returned the number of seconds from last midnight, and its accuracy was 1/18 secs

 

See also

 

Time

Sleep