Advertisement
Guest User

Code

a guest
Apr 2nd, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import time
  2. import functools
  3.  
  4. def profiler(function):
  5.     @functools.wraps(function)
  6.     def wrapped_func(*args, **kwargs):
  7.         if not hasattr(wrapped_func, 'depth'):
  8.             wrapped_func.depth = 0
  9.         wrapped_func.depth+=1
  10.        
  11.         if wrapped_func.depth==1:
  12.             wrapped_func.calls=0
  13.         wrapped_func.calls += 1
  14.        
  15.         time0=time.time()
  16.         answer = function(*args, **kwargs)
  17.         time1=time.time()
  18.         wrapped_func.last_time_taken=time1-time0
  19.        
  20.        
  21.         wrapped_func.depth-=1
  22.         return answer
  23.     return wrapped_func
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement