Skip to content

Instantly share code, notes, and snippets.

@kylecorry31
Created January 7, 2015 23:45
Show Gist options
  • Save kylecorry31/9143cdcedc822edf77b9 to your computer and use it in GitHub Desktop.
Save kylecorry31/9143cdcedc822edf77b9 to your computer and use it in GitHub Desktop.
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