Skip to content

Commit fc41ff5

Browse files
authored
Create decorators_burakhan_gultoplar.py
1 parent 71f5b39 commit fc41ff5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
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 update_wrapper
4+
5+
6+
class performance:
7+
counter = 0
8+
total_time = 0.0
9+
total_mem = 0
10+
11+
def __init__(self, fn):
12+
self.fn = fn
13+
update_wrapper(self, fn)
14+
15+
def __call__(self, *args, **kwargs):
16+
tracemalloc.start()
17+
t0 = time.perf_counter()
18+
19+
out = self.fn(*args, **kwargs)
20+
21+
t1 = time.perf_counter()
22+
_, peak = tracemalloc.get_traced_memory()
23+
tracemalloc.stop()
24+
25+
performance.counter += 1
26+
performance.total_time += (t1 - t0)
27+
performance.total_mem += peak
28+
29+
return out

0 commit comments

Comments
 (0)