Created
July 7, 2016 05:20
-
-
Save mpurdon/f5363b27b67f71620da5fbdd9fbbdd58 to your computer and use it in GitHub Desktop.
The sleep function is not very precise, this basically checks how bad it is on your system.
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 | |
from datetime import datetime | |
def check_sleep(amount): | |
start = datetime.now() | |
time.sleep(amount) | |
end = datetime.now() | |
delta = end-start | |
return delta.seconds + delta.microseconds/1000000. | |
if __name__ == '__main__': | |
error = sum(abs(check_sleep(0.050)-0.050) for i in xrange(100))*10 | |
print "Average error is %0.3fms" % error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment