Feature or enhancement
Proposal:
@functools.track_stats
def my_task():
# process data
pass
my_task()
print(my_task.get_stats().average_time)
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
I propose adding a new decorator called @track_stats to the functools module. This tool allows developers to monitor function performance (call count and execution time) in a simple and "pythonic" way without the overhead of full profiling tools like cProfile.
Motivation
Currently, there is no intermediate tool in the standard library to measure how many times a function is called and its total/average execution time. This is especially useful for university projects, auditing code, and optimizing algorithms during development.
Specification
The decorator adds a .get_stats() method to the wrapped function, which returns an object containing:
calls: Integer count of invocations.
total_time: Total seconds spent in the function using time.perf_counter().
average_time: The average duration per call.
Feature or enhancement
Proposal:
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
I propose adding a new decorator called @track_stats to the functools module. This tool allows developers to monitor function performance (call count and execution time) in a simple and "pythonic" way without the overhead of full profiling tools like cProfile.
Motivation
Currently, there is no intermediate tool in the standard library to measure how many times a function is called and its total/average execution time. This is especially useful for university projects, auditing code, and optimizing algorithms during development.
Specification
The decorator adds a .get_stats() method to the wrapped function, which returns an object containing:
calls: Integer count of invocations.
total_time: Total seconds spent in the function using time.perf_counter().
average_time: The average duration per call.