Skip to content

Commit cd2eb6f

Browse files
authored
Merge pull request #871 from efesarigul/patch-6
Add performance decorator to track function metrics
2 parents 144a299 + 32243bf commit cd2eb6f

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 _performance(*args, **kwargs):
7+
performance.counter += 1
8+
tracemalloc.start()
9+
start = time.perf_counter()
10+
result = func(*args, **kwargs)
11+
end = time.perf_counter()
12+
current, peak = tracemalloc.get_traced_memory()
13+
tracemalloc.stop()
14+
performance.total_time += end - start
15+
performance.total_mem += peak
16+
return result
17+
return _performance
18+
19+
20+
performance.counter = 0
21+
performance.total_time = 0
22+
performance.total_mem = 0

0 commit comments

Comments
 (0)