Skip to content

Commit ef84fdd

Browse files
authored
Add performance tracking decorator
1 parent c303a2a commit ef84fdd

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import time
2+
import tracemalloc
3+
4+
5+
def performance(func):
6+
def wrapper(*args, **kwargs):
7+
performance.counter += 1
8+
tracemalloc.start()
9+
start = time.perf_counter()
10+
result = func(*args, **kwargs)
11+
performance.total_time += time.perf_counter() - start
12+
performance.total_mem += tracemalloc.get_traced_memory()[1]
13+
tracemalloc.stop()
14+
return result
15+
return wrapper
16+
17+
18+
19+
20+
performance.counter = 0
21+
performance.total_time = 0
22+
performance.total_mem = 0

0 commit comments

Comments
 (0)