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-27 00:33:28 -04:00
|
|
|
def sleep_ms(ms):
|
|
|
|
# type: (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-27 00:33:28 -04:00
|
|
|
def ticks_ms():
|
|
|
|
# type: () -> 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-27 00:33:28 -04:00
|
|
|
def ticks_diff(new, old):
|
|
|
|
# type: (float, float) -> float
|
2020-10-21 12:19:42 -07:00
|
|
|
return new - old
|
|
|
|
|
|
|
|
|
2021-08-27 00:33:28 -04:00
|
|
|
def accurate_ticks():
|
|
|
|
# type: () -> int
|
2020-10-21 12:19:42 -07:00
|
|
|
'''Is more expensive, but good for time critical things'''
|
|
|
|
return time.monotonic_ns()
|
|
|
|
|
|
|
|
|
2021-08-27 00:33:28 -04:00
|
|
|
def accurate_ticks_diff(new, old, ms):
|
|
|
|
# type: (float, float, float) -> bool
|
2020-10-21 12:19:42 -07:00
|
|
|
return bool(new - old < ms * 1000000)
|