We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 71f5b39 commit cb9b51aCopy full SHA for cb9b51a
Week04/decorators_mehmet_usta.py
@@ -0,0 +1,23 @@
1
+def performance(func):
2
+ if not hasattr(performance, "counter"):
3
+ performance.counter = 0
4
+ performance.total_time = 0.0
5
+ performance.total_mem = 0
6
+
7
+ def wrapper(*args, **kwargs):
8
+ start_time = time.perf_counter()
9
+ tracemalloc.start()
10
11
+ result = func(*args, **kwargs)
12
13
+ current, peak = tracemalloc.get_traced_memory()
14
+ tracemalloc.stop()
15
+ end_time = time.perf_counter()
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