Library API

Timestamp Functions

win_precise_time.time() float

Return the time in seconds since the epoch as a floating point number. See time.time() for a detailed description. This function provides a timestamp with <1us resolution while the builtin time() function has a resolution of around 15ms.

Returns:

timestamp in seconds

win_precise_time.time_ns() int

Similar to time() but returns time as an integer number of nanoseconds since the epoch.

Returns:

timestamp in nanoseconds

Sleep Functions

win_precise_time.sleep(secs: float, /) None

Suspend execution of the calling thread for the given number of seconds. See time.sleep() for a detailed description. This function provides the same accuracy as the Python 3.11 implementation. Earlier Python version were unable to achieve sub-millisecond precision.

Parameters:

secs (float) – the sleep duration in seconds

win_precise_time.sleep_until(t_wakeup_s: float, /) None

Suspend execution of the calling thread until time() == t_wakeup_s.

Parameters:

t_wakeup_s (float) – the wakeup time in seconds since the epoch

win_precise_time.sleep_until_ns(t_wakeup_ns: int, /) None

Suspend execution of the calling thread until time_ns() == t_wakeup_ns.

Parameters:

t_wakeup_ns (int) – the wakeup times in nanoseconds since the epoch

win_precise_time.hotloop_until_ns(t_wakeup_ns: int, /) None

Run a busy loop until time_ns() == t_wakeup_ns. This function fully loads the CPU core and does not release the global interpreter lock (GIL). This function must only be used for very short wait time to achieve the highest wakeup time precision.

Parameters:

t_wakeup_ns (int) – the wakeup time in nanoseconds since the epoch

Warning

hotloop_until_ns() makes the process unresponsive. It is only useful for very short high precision waiting.