tests/extmod: Add test to compare time_ns with time.

They should be close together.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2024-10-24 17:56:50 +11:00
parent 1ec0c9b886
commit 09ea901317
2 changed files with 17 additions and 0 deletions

View File

@ -22,3 +22,10 @@ if 2000000 < t1 - t0 < 50000000:
print(True) print(True)
else: else:
print(t0, t1, t1 - t0) print(t0, t1, t1 - t0)
# Check that time.time() and time.time_ns() are within a second of each other.
# Note that time.time() may return an int or float.
for _ in range(10):
t_s, t_ns = time.time(), time.time_ns()
print(abs(t_s * 1_000 - t_ns // 1_000_000) <= 1_000)
time.sleep_us(100_000)

View File

@ -1,2 +1,12 @@
True True
True True
True
True
True
True
True
True
True
True
True
True