Created
March 9, 2018 14:33
-
-
Save norbinsh/ffcd3a55463f12bc9e71b44e31272646 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
""" | |
Playing around with decorators. | |
""" | |
__author__ = 'Shay Elmualem' | |
import time | |
def calc_func_runtime(func): | |
def wrapper(): | |
start = int(time.time()) | |
func() | |
end = int(time.time()) | |
return f'Time it took for {func} to finish execution: {end - start}' | |
return wrapper | |
@calc_func_runtime | |
def sleep_please(): | |
time.sleep(3) | |
@calc_func_runtime | |
def sleep_longer(): | |
time.sleep(10) | |
print(sleep_please()) | |
print(sleep_longer()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment