Skip to content

Instantly share code, notes, and snippets.

@mpurdon
Created July 7, 2016 05:20
Show Gist options
  • Save mpurdon/f5363b27b67f71620da5fbdd9fbbdd58 to your computer and use it in GitHub Desktop.
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.
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