Created
May 21, 2012 04:34
-
-
Save Arachnid/2760563 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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