Last active
June 14, 2019 09:16
-
-
Save o3o3o/0cac89899e2870440c3dae7412a4529c to your computer and use it in GitHub Desktop.
log the duration of calling function
This file contains hidden or 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
| 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