Created
July 10, 2020 00:17
-
-
Save secantsquared/791c9121bae7875b001f7e75f23a7e8c to your computer and use it in GitHub Desktop.
simple decorator to approximate run time for basic functions
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(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| t_initial = time.perf_counter() | |
| value = func(*args, **kwargs) | |
| t_final = time.perf_counter() - t_initial | |
| print(f"{func.__name__!r} finished in {t_final-t_initial:0.4f} secs.") | |
| return value | |
| return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment