Skip to content

Commit 4966edc

Browse files
authored
Merge pull request #812 from onurkonukk/patch-5
Create decorators_onur_konuk.py
2 parents 133e6cb + 8a17d3b commit 4966edc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Week04/decorators_onur_konuk.py

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

0 commit comments

Comments
 (0)