import random
import time
# PythonDecorators/entry_exit_class.py
class execution_time_calculator(object):
def __init__(self, f):
self.f = f
def __call__(self):
start = int(round(time.time() * 1000))
print("Entering", self.f.__name__)
self.f()
end = int(round(time.time() * 1000))
#print("Exited", self.f.__name__)
print("Time taken : "+str((end-start)) + ' milli seconds')
@execution_time_calculator
def func1():
seconds = random.randint(5, 15)
print("inside func2() sleeping for "+str(seconds) + " seconds")
time.sleep(seconds)
Entering func1
inside func2() sleeping for 13 seconds
Time taken : 13007 milli seconds