Created
September 2, 2020 22:47
-
-
Save ycui1/ea64f9687f5b4e3b519ed21f96626766 to your computer and use it in GitHub Desktop.
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
>>> import time | |
... from functools import wraps | |
... | |
... def logging_time(unit): | |
... """Decorator that logs time""" | |
... def logger(func): | |
... @wraps(func) | |
... def inner_logger(*args, **kwargs): | |
... """Function that logs time""" | |
... start = time.time() | |
... func(*args, **kwargs) | |
... scaling = 1000 if unit == "ms" else 1 | |
... print(f"Calling {func.__name__}: {(time.time() - start) * scaling:.5f} {unit}") | |
... | |
... return inner_logger | |
... | |
... return logger | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment