Repository navigation
Timer
Home › Date and Time Functions › Timer
Returns the seconds since a fixed starting point, for measuring elapsed time.
Declare Function Timer ( ) As DoubleThe Timer function is useful for finding out how long a section of code takes to run, or for control the timing of your code. To find out how much time has passed between two points in your program, you can 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).
Returns a Double precision result with the time, in seconds, since a static reference point.
result = Timer
- On Win32 and Linux, if the program must wait for periods of 0.1 seconds or more,
Sleepshould 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 is therefore 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
-
The precision of TIMER varies, depending on the computer used. If the processor has a precision timer (as the Performance Counter Pentium processors from Intel have) and the OS uses it, the precision is linked to the processor clock and microseconds can be expected. With older processors (386, 486), and always in DOS, the resolution is 1/18 second.
Usage of TIMER can cause disk accesses in DOS, see forum for analysis and solutions
- In QB, TIMER returned the number of seconds from last midnight, and its accuracy was 1/18 secs
'' Example of using TIMER function
'' Note: see text about correct waiting strategies
Dim Start As Double
Print "Wait 2.5 seconds."
Start = Timer
Do
Sleep 1, 1
Loop Until (Timer - Start) > 2.5
Print "Done."Category: Date and Time Functions
Kind: function
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing