codeflash/code_to_optimize/sleeptime.py

11 lines
225 B
Python
Raw Permalink Normal View History

import time
2024-10-23 21:38:23 +00:00
def accurate_sleepfunc(t) -> float:
"""T is in seconds"""
start_time = time.perf_counter_ns()
while True:
if (time.perf_counter_ns() - start_time) / 10e9 >= t:
break
return t