Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import functools
- def profiler(function):
- @functools.wraps(function)
- def wrapped_func(*args, **kwargs):
- if not hasattr(wrapped_func, 'depth'):
- wrapped_func.depth = 0
- wrapped_func.depth+=1
- if wrapped_func.depth==1:
- wrapped_func.calls=0
- wrapped_func.calls += 1
- time0=time.time()
- answer = function(*args, **kwargs)
- time1=time.time()
- wrapped_func.last_time_taken=time1-time0
- wrapped_func.depth-=1
- return answer
- return wrapped_func
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement