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 c1ed83fCopy full SHA for c1ed83f
Week04/decorators_recepkadir_altıntaş.py
@@ -0,0 +1,26 @@
1
+import time
2
+import tracemalloc
3
+import functools
4
+
5
+def performance(func):
6
+ @functools.wraps(func)
7
+ def wrapper(*args, **kwargs):
8
+ tracemalloc.start()
9
+ start_time = time.perf_counter()
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
+ return wrapper
23
24
+performance.counter = 0
25
+performance.total_time = 0
26
+performance.total_mem = 0
0 commit comments