Skip to content

Commit 72ce19e

Browse files
authored
Create decorators_aycaselda_keskin.py
1 parent 9a399e7 commit 72ce19e

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)