Skip to content

Commit 7c018ec

Browse files
authored
Update decorators_murad_maharramli,py
1 parent 1713ba2 commit 7c018ec

1 file changed

Lines changed: 1 addition & 7 deletions

File tree

Week04/decorators_murad_maharramli,py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,28 @@ from functools import wraps
55
def performance(func):
66
"""
77
A decorator that measures the performance of functions and saves statistics.
8-
Attributes are stored directly on the 'performance' function object to satisfy test assertions.
98
"""
109
@wraps(func)
1110
def wrapper(*args, **kwargs):
12-
# Increment the global decorator call counter
1311
performance.counter += 1
1412

15-
# Start tracking memory and time
1613
tracemalloc.start()
1714
start_time = time.perf_counter()
1815

19-
# Execute the original function
2016
result = func(*args, **kwargs)
2117

22-
# Stop tracking and calculate consumed resources
2318
end_time = time.perf_counter()
2419
_, peak_mem = tracemalloc.get_traced_memory()
2520
tracemalloc.stop()
2621

27-
# Update the global decorator tracking attributes
2822
performance.total_time += (end_time - start_time)
2923
performance.total_mem += peak_mem
3024

3125
return result
3226

3327
return wrapper
3428

35-
# Initialize the required attributes on the decorator itself
29+
# Initialize the required tracking attributes on the decorator
3630
performance.counter = 0
3731
performance.total_time = 0.0
3832
performance.total_mem = 0

0 commit comments

Comments
 (0)