Created
May 28, 2018 06:41
-
-
Save jacekmigacz/56a2ed4760284a1f785c78f9d3fe3ebd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def busy_sleep(secs): | |
sts, lts = time.perf_counter(), time.perf_counter() | |
mf = 0 | |
while True: | |
nts = time.perf_counter() | |
dt = nts - sts | |
if dt + mf >= secs: | |
break | |
if nts != lts: | |
mf = max(mf, nts - lts) | |
lts = nts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment