Created
January 7, 2015 23:45
-
-
Save kylecorry31/9143cdcedc822edf77b9 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 | |
import cProfile | |
def timedcall(fn, *args): | |
t0 = time.clock() | |
result = fn(*args) | |
t1 = time.clock() | |
return t1-t0, result | |
def timedcalls(n, fn, *args): | |
if isinstance(n, int): | |
times = [timedcall(fn, *args)[0] for _ in range(n)] | |
else: | |
times = [] | |
while sum(times) <= n: | |
times.append(timedcall(fn, *args)[0]) | |
return min(times), average(times), max(times) | |
def average(numbers): | |
return sum(numbers) / len(numbers) | |
def profile(fn, *args): | |
cProfile.run(fn, *args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment