2018-10-16 13:04:39 +02:00
|
|
|
import time
|
2018-10-17 07:43:47 +02:00
|
|
|
|
2018-10-07 09:44:04 +02:00
|
|
|
|
|
|
|
def sleep_ms(ms):
|
2020-10-21 21:19:42 +02:00
|
|
|
return time.sleep(ms / 1000)
|
2018-09-28 23:35:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
def ticks_ms():
|
2020-10-21 21:19:42 +02:00
|
|
|
'''Has .25s granularity, but is cheap'''
|
|
|
|
return time.monotonic() * 1000
|
2018-09-28 23:35:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
def ticks_diff(new, old):
|
2020-10-21 21:19:42 +02: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)
|