2018-10-16 04:04:39 -07:00
|
|
|
import time
|
2018-10-16 22:43:47 -07:00
|
|
|
|
2018-10-07 00:44:04 -07:00
|
|
|
|
2021-08-15 21:23:02 +00:00
|
|
|
def sleep_ms(ms: float) -> None:
|
2020-10-21 12:19:42 -07:00
|
|
|
return time.sleep(ms / 1000)
|
2018-09-28 14:35:52 -07:00
|
|
|
|
|
|
|
|
2021-08-15 21:23:02 +00:00
|
|
|
def ticks_ms() -> float:
|
2020-10-21 12:19:42 -07:00
|
|
|
'''Has .25s granularity, but is cheap'''
|
|
|
|
return time.monotonic() * 1000
|
2018-09-28 14:35:52 -07:00
|
|
|
|
|
|
|
|
2021-08-15 21:23:02 +00:00
|
|
|
def ticks_diff(new: float, old: float) -> float:
|
2020-10-21 12:19:42 -07:00
|
|
|
return new - old
|
|
|
|
|
|
|
|
|
2021-08-15 21:23:02 +00:00
|
|
|
def accurate_ticks() -> int:
|
2020-10-21 12:19:42 -07:00
|
|
|
'''Is more expensive, but good for time critical things'''
|
|
|
|
return time.monotonic_ns()
|
|
|
|
|
|
|
|
|
2021-08-15 21:23:02 +00:00
|
|
|
def accurate_ticks_diff(new: float, old: float, ms: float) -> bool:
|
2020-10-21 12:19:42 -07:00
|
|
|
return bool(new - old < ms * 1000000)
|