Timer utils
timer_utils
#
Functions:
Name | Description |
---|---|
timed_context |
Context manager to measure the execution time of a block of code and log it with a custom name. |
timer |
Decorator to measure the execution time of a function and log it with a custom name. |
timed_context
#
timed_context(
name: str,
) -> imgtools.utils.timer_utils.TimerContext
Context manager to measure the execution time of a block of code and log it with a custom name.
Returns:
Type | Description |
---|---|
TimerContext:
|
A context manager that measures the execution time of a block of code. |
Example
with timed_context("My Block"):
# do something
# Output: `My Block took 3.1244 seconds`
Source code in src/imgtools/utils/timer_utils.py
timer
#
timer(
name: str,
) -> typing.Callable[
[typing.Callable[..., typing.Any]],
typing.Callable[..., typing.Any],
]
Decorator to measure the execution time of a function and log it with a custom name.
Returns:
Type | Description |
---|---|
Callable[[Callable[..., Any]], Callable[..., Any]]:
|
A decorator that wraps the function to measure its execution time. |
Example
@timer("My Function")
def my_function():
# do something
my_function()
# Output: `My Function took 3.1244 seconds`