A small Python project implementing three decorators for measuring execution time, tracking memory usage, and logging function calls.
Measures how long a function takes to execute using time.perf_counter().
Tracks current and peak Python memory allocations fora method execution using tracemalloc.
Logs information about function calls...
Import the decorators and apply them to a function:
from time_decorator import measure_time
from memory_decorator import measure_memory
from log_decorator import log
@log
@measure_time
@measure_memory
def big_list():
return [x for x in range(1_000_000)]
big_list()The decorators can be combined to measure different aspects of a function's execution.
python test.py
Current memory: 3.12 KB
Peak memory: 1964780.38 KB
big_list took 42.94 seconds to be executed
It is recommended to add in your IDE the path to the project so it recognizes the library. In VScode for example you have to add the following code to the settings.json file of your vscode:
"python.analysis.extraPaths":[
"D:/REPLACE_WITH_PATH.../time-memory-decorators-python"
],
- Python
- time
- tracemalloc
- functools wraps