Skip to content

Commit e301544

Browse files
authored
Create decorators_ege_enc.py
1 parent 71f5b39 commit e301544

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Week04/decorators_ege_enc.py

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

0 commit comments

Comments
 (0)