Skip to content

Instantly share code, notes, and snippets.

@HoweChen
Last active February 20, 2019 09:25
Show Gist options
  • Save HoweChen/741cff3728f60e6bb3c56c6350f391bf to your computer and use it in GitHub Desktop.
Save HoweChen/741cff3728f60e6bb3c56c6350f391bf to your computer and use it in GitHub Desktop.
[Python timing wrapper]The python timing wrapper #Python
from functools import wraps
from time import time
def timing(f):
@wraps(f)
def wrap(*args, **kw):
ts = time()
result = f(*args, **kw)
te = time()
print(
f"func: {f.__name__}\nargs:[{args}, {kwargs}]\ntook: {t_end-t_start} sec")
return result
return wrap
@timing
def f(a):
for _ in range(a):
i = 0
return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment