Skip to content

Instantly share code, notes, and snippets.

@o3o3o
Last active June 14, 2019 09:16
Show Gist options
  • Select an option

  • Save o3o3o/0cac89899e2870440c3dae7412a4529c to your computer and use it in GitHub Desktop.

Select an option

Save o3o3o/0cac89899e2870440c3dae7412a4529c to your computer and use it in GitHub Desktop.
log the duration of calling function
import time
from functools import wraps
def timeit(method):
@wraps(method)
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
print(
"timeit: %r (%r, %r) duration: %s sec"
% (method.__name__, args, kw, te - ts)
)
return result
return timed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment