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
|
|
|
|
|
|
|
def sleep_ms(ms):
|
2020-10-21 12:19:42 -07:00
|
|
|
return time.sleep(ms / 1000)
|
2018-09-28 14:35:52 -07:00
|
|
|
|
|
|
|
|
|
|
|
def ticks_ms():
|
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
|
|
|
|
|
|
|
|
|
|
|
def ticks_diff(new, old):
|
2020-10-21 12:19:42 -07:00
|
|
|
return new - old
|
|
|
|
|
|
|
|
|
|
|
|
def accurate_ticks():
|
|
|
|
'''Is more expensive, but good for time critical things'''
|
|
|
|
return time.monotonic_ns()
|
|
|
|
|
|
|
|
|
|
|
|
def accurate_ticks_diff(new, old, ms):
|
|
|
|
return bool(new - old < ms * 1000000)
|