Created
February 7, 2020 06:28
-
-
Save arpitbbhayani/9fca21f955fa896bbbd592cf10a32eb7 to your computer and use it in GitHub Desktop.
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 | |
def my_decorator(fn): | |
"""my_decorator is a custom decorator that wraps any function | |
and prints on stdout the time for execution. | |
""" | |
def wrapper_function(*args, **kwargs): | |
start_time = time.time() | |
# invoking the wrapped function and getting the return value. | |
value = fn(*args, **kwargs) | |
print("the function execution took:", time.time() - start_time, "seconds") | |
# returning the value got after invoking the wrapped function | |
return value | |
return wrapper_function | |
@my_decorator | |
def area(l, b): | |
return l * b | |
>>> area(3, 4) | |
the function execution took: 9.5367431640625e-07 seconds | |
12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment