Skip to content

Instantly share code, notes, and snippets.

@ycui1
Last active September 2, 2020 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycui1/f7b3cf8e943b4178cab66e38a73e03a2 to your computer and use it in GitHub Desktop.
Save ycui1/f7b3cf8e943b4178cab66e38a73e03a2 to your computer and use it in GitHub Desktop.
>>> 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