Last active
September 2, 2020 09:16
-
-
Save ycui1/f7b3cf8e943b4178cab66e38a73e03a2 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 | |
... def logging_time(func): | |
... """Decorator that logs time""" | |
... def logger(): | |
... """Function that logs time""" | |
... start = time.time() | |
... func() | |
... print(f"Calling {func.__name__}: {time.time() - start:.5f}") | |
... | |
... return logger | |
... | |
... @logging_time | |
... def calculate_sum(): | |
... return sum(range(10000)) | |
... | |
... calculate_sum() | |
... | |
Calling calculate_sum: 0.00018 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment