We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 2060eb2 + 52a068b commit e99952cCopy full SHA for e99952c
1 file changed
Week04/decorators_burak_sartik.py
@@ -0,0 +1,27 @@
1
+import time
2
+import tracemalloc
3
+
4
+def performance(func):
5
+ if not hasattr(performance, 'counter'):
6
+ performance.counter = 0
7
+ performance.total_time = 0.0
8
+ performance.total_mem = 0.0
9
+ def wrapper(*args, **kwargs):
10
+ tracemalloc.start()
11
+ start_time = time.perf_counter()
12
13
+ result = func(*args, **kwargs)
14
15
+ end_time = time.perf_counter()
16
+ current_mem, peak_mem = tracemalloc.get_traced_memory()
17
+ tracemalloc.stop()
18
19
+ performance.counter += 1
20
+ performance.total_time += (end_time - start_time)
21
+ performance.total_mem += peak_mem
22
23
+ return result
24
+ wrapper.__name__ = func.__name__
25
+ wrapper.__doc__ = func.__doc__
26
27
+ return wrapper
0 commit comments