Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
>>> 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