Advertisement
Guest User

n5

a guest
Mar 31st, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. import time
  2. import functools
  3.  
  4.  
  5. def profiler(func):
  6. profiler.calls = 0
  7. profiler.bal = 0
  8.  
  9. @functools.wraps(func)
  10. def wrapper(*args, **kwargs):
  11. if profiler.bal == 0:
  12. profiler.calls = 0
  13.  
  14. profiler.bal += 1
  15. to = time.time()
  16. profiler.calls += 1
  17. wrapper.calls = profiler.calls
  18.  
  19. answer = func(*args, **kwargs)
  20. wrapper.last_time_taken = time.time() - to
  21. profiler.bal -= 1
  22. return answer
  23. return wrapper
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement