I create a decorator to time the cost of every funcions :
def timmer(func):
def wrapper(*args, **kwargs):
start_time = time.time()
res = func(*args, **kwargs)
stop_time = time.time()
print('Func %s, run time: %s' % (func.__name__, stop_time - start_time))
return res
return wrapper
And use it every def , for example :
@timmer
def Test_func(*args,**kwargs):
return "hello !"
Then I can obtain the cost time of every func.
But if I do this , I have to use @timmer in every def .If this .py file has 100 defs , then I must use @timmer for 100 times.
How can I get the running time of each method conveniently ?