Created
July 20, 2021 09:59
-
-
Save discort/5657788cb279b07749dc6d62a79f102d to your computer and use it in GitHub Desktop.
Timing decorator
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
# https://stackoverflow.com/a/27737385/3960038 | |
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('func:%r took: %2.4f sec' % (f.__name__, te-ts)) | |
return result | |
return wrap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment