libstd/time
Clocks, timestamps, sleeping and measuring durations, over clock_gettime/clock_nanosleep.
#include <libstd/time>
Same functions and constant names on Linux and Windows: the system-specific part is in wrapper/linux/systime and wrapper/windows/systime (see Linux and Windows).
Example
#include <libstd/stdio>
#include <libstd/time>
t0 = new Timespec()
monotonic(t0)
sleep_ms(150 as long)
print("elapsed: ", since_ms(t0), " ms\n") // >= 150
print("now: ", timestamp(), " s since the epoch\n")
Constants
| Name | Linux | Windows | Meaning |
|---|---|---|---|
CLOCK_REALTIME | 0 | 0 | |
CLOCK_MONOTONIC | 1 | 1 | |
CLOCK_MONOTONIC_RAW | 4 | 4 | |
CLOCK_BOOTTIME | 7 | 7 | |
CLOCK_PROCESS_CPUTIME_ID | 2 | 2 | |
CLOCK_THREAD_CPUTIME_ID | 3 | 3 | |
TIMER_RELATIVE | 0 | 0 | |
TIMER_ABSTIME | 1 | 1 |
Classes
Seconds and microseconds.
tv_sec long
tv_usec longSeconds and nanoseconds, as written by the clock syscalls.
tv_sec long
tv_nsec longFunctions
Wall-clock time (CLOCK_REALTIME) into tp.
Monotonic time (CLOCK_MONOTONIC) into tp: for measuring durations.
Seconds since the Unix epoch.
Milliseconds since the Unix epoch.
Milliseconds between two instants (typically from monotonic).
Milliseconds elapsed from start until now.
Sleeps for the given milliseconds (a signal can end it early, silently).
Sleeps for the given seconds.
CPU time consumed by the process so far, all threads, in milliseconds.
CPU time consumed by the calling thread, in milliseconds.
Resolution of a clock in nanoseconds.
Sets a clock (needs privileges).
Reads a clock into a Timespec.
Reads the resolution of a clock into a Timespec.
Sleeps for request (relative or absolute, see flags); the remaining time on interruption is written to remain.