File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,34 +5,28 @@ from functools import wraps
55def 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
3630performance.counter = 0
3731performance.total_time = 0.0
3832performance.total_mem = 0
You can’t perform that action at this time.
0 commit comments