Skip to content

Instantly share code, notes, and snippets.

@Arachnid
Created May 21, 2012 04:34
Show Gist options
  • Save Arachnid/2760563 to your computer and use it in GitHub Desktop.
Save Arachnid/2760563 to your computer and use it in GitHub Desktop.
from datetime import datetime, timedelta
import time
def check_sleep(func, amt):
start = datetime.now()
func(amt)
end = datetime.now()
delta = end-start
return abs(delta.seconds + delta.microseconds/1000000.0 - amt)
def percent_error(func, amt, times):
error = sum(check_sleep(func, amt) for i in range(times)) / times
return error / amt
def busy_sleep(amt):
start = time.time()
while time.time() < start + amt: pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment