Skip to content

Instantly share code, notes, and snippets.

@norbinsh
Created March 9, 2018 14:33
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 norbinsh/ffcd3a55463f12bc9e71b44e31272646 to your computer and use it in GitHub Desktop.
Save norbinsh/ffcd3a55463f12bc9e71b44e31272646 to your computer and use it in GitHub Desktop.
"""
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