Skip to content

Commit bdaa971

Browse files
Update decorators_fevzi_bagriacik.py
1 parent 3feefad commit bdaa971

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import time
22
import tracemalloc
3-
from functools import update_wrapper
3+
from functools import wraps
44

55

66
class performance:
7-
"""
8-
A decorator which measures the performance of functions and
9-
also saves some statistics.
10-
"""
7+
counter = 0
8+
total_time = 0.0
9+
total_mem = 0
1110

1211
def __init__(self, func):
1312
self.func = func
14-
self.counter = 0
15-
self.total_time = 0.0
16-
self.total_mem = 0
17-
update_wrapper(self, func)
13+
wraps(func)(self)
1814

1915
def __call__(self, *args, **kwargs):
2016
tracemalloc.start()
@@ -26,8 +22,8 @@ def __call__(self, *args, **kwargs):
2622
current, peak = tracemalloc.get_traced_memory()
2723
tracemalloc.stop()
2824

29-
self.counter += 1
30-
self.total_time += (end_time - start_time)
31-
self.total_mem += peak
25+
performance.counter += 1
26+
performance.total_time += (end_time - start_time)
27+
performance.total_mem += peak
3228

3329
return result

0 commit comments

Comments
 (0)