Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import time
from functools import wraps
def benchmark(method):
"""
Benchmark decorator, a quick and convenient way to time a function
:param method: function it wraps
:return: decorated function
"""
@wraps(method)
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
args_str = (str(args)[:75] + ' ... ') if len(str(args)) > 75 else str(args)
print('%r: started: %2.3f, ran: %2.3f sec' % (method.__name__, ts, te-ts))
return result
return timed