2022-08-18 02:57:45 -04:00
|
|
|
# test time.time_ns()
|
2020-09-23 22:37:02 -04:00
|
|
|
|
|
|
|
try:
|
2022-08-18 02:57:45 -04:00
|
|
|
import time
|
2020-09-23 22:37:02 -04:00
|
|
|
|
2022-08-18 02:57:45 -04:00
|
|
|
time.sleep_us
|
|
|
|
time.time_ns
|
2020-09-23 22:37:02 -04:00
|
|
|
except (ImportError, AttributeError):
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
|
|
|
|
2022-08-18 02:57:45 -04:00
|
|
|
t0 = time.time_ns()
|
|
|
|
time.sleep_us(5000)
|
|
|
|
t1 = time.time_ns()
|
2020-09-23 22:37:02 -04:00
|
|
|
|
|
|
|
# Check that time_ns increases.
|
|
|
|
print(t0 < t1)
|
|
|
|
|
2021-02-01 02:44:28 -05:00
|
|
|
# Check that time_ns counts correctly, but be very lenient with the bounds (2ms to 50ms).
|
|
|
|
if 2000000 < t1 - t0 < 50000000:
|
2020-09-23 22:37:02 -04:00
|
|
|
print(True)
|
|
|
|
else:
|
|
|
|
print(t0, t1, t1 - t0)
|