Skip to content

Commit cbf4489

Browse files
authored
Create decorators_roca_ozdaman.py
1 parent 71f5b39 commit cbf4489

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Week04/decorators_roca_ozdaman.py

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

0 commit comments

Comments
 (0)