Skip to content

Commit f67d66b

Browse files
author
Seher Arslanbay
committed
decorators seher arslanbay
1 parent 81596f3 commit f67d66b

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
import time
3+
import tracemalloc
4+
from functools import wraps
5+
6+
7+
def performance(func):
8+
@wraps(func)
9+
def wrapper(*args, **kwargs):
10+
performance.counter += 1
11+
12+
tracemalloc.start()
13+
start_time = time.perf_counter()
14+
15+
try:
16+
result = func(*args, **kwargs)
17+
finally:
18+
elapsed_time = time.perf_counter() - start_time
19+
current_mem, peak_mem = tracemalloc.get_traced_memory()
20+
tracemalloc.stop()
21+
22+
performance.total_time += elapsed_time
23+
performance.total_mem += peak_mem
24+
25+
return result
26+
27+
return wrapper
28+
29+
30+
performance.counter = 0
31+
performance.total_time = 0.0
32+
performance.total_mem = 0

0 commit comments

Comments
 (0)