Skip to content

Commit f64ac9c

Browse files
authored
Create decorators_zahra_ismayilli.py
1 parent 2024d08 commit f64ac9c

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)