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