emrpy.decorators
Function Decorators
Execution profiling utilities for measuring runtime and memory usage.
Functions
|
Decorator to measure and print the execution time of a function. |
|
Decorator to measure execution time and peak memory usage of a function. |
- emrpy.decorators.timer(func)
Decorator to measure and print the execution time of a function.
Parameters:
- funcCallable
The function to time.
Returns:
: Callable
Wrapped function that prints execution duration on each call.
Examples:
>>> @timer ... def slow_fn(): ... time.sleep(2)
>>> slow_fn() Function 'slow_fn' executed in 2.00 seconds.
- emrpy.decorators.timer_and_memory(func)
Decorator to measure execution time and peak memory usage of a function.
Uses tracemalloc to track memory allocations and prints both runtime and peak memory in megabytes after function execution.
Parameters:
- funcCallable
The function to profile.
Returns:
: Callable
Wrapped function that prints runtime and memory usage on each call.
Examples:
>>> @timer_and_memory ... def compute(): ... data = [x**2 for x in range(10**6)]
>>> compute() Function 'compute' executed in 0.12 seconds and Peak memory usage: 45.231 MB.