Skip to content

Commit 41bd6d9

Browse files
authored
Create decorators_Sevval_Ok.py
1 parent 71f5b39 commit 41bd6d9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Week04/decorators_Sevval_Ok.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
wrapper.counter += 1
10+
11+
tracemalloc.start()
12+
start_time = time.perf_counter()
13+
14+
result = func(*args, **kwargs)
15+
16+
end_time = time.perf_counter()
17+
current, peak = tracemalloc.get_traced_memory()
18+
tracemalloc.stop()
19+
20+
wrapper.total_time += (end_time - start_time)
21+
wrapper.total_mem += peak
22+
23+
return result
24+
25+
wrapper.counter = 0
26+
wrapper.total_time = 0.0
27+
wrapper.total_mem = 0
28+
29+
return wrapper

0 commit comments

Comments
 (0)