From 91938c2bb6b93d0a74ec5470a522d337001c2d2b Mon Sep 17 00:00:00 2001 From: "Mohcine Chraibi (aider)" Date: Thu, 17 Oct 2024 11:38:09 +0900 Subject: [PATCH] docs: Enhance docstring for profile_function --- sim_delme.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/sim_delme.py b/sim_delme.py index 1638f95..7a3e37e 100644 --- a/sim_delme.py +++ b/sim_delme.py @@ -63,9 +63,26 @@ def write_value_to_file(file_handle: _io.TextIOWrapper, value: str) -> None: @contextlib.contextmanager def profile_function(name: str) -> Iterator[None]: - """Profile function. use with and name it .""" + """Measure and log the execution time of a block of code. + + This function is intended to be used as a context manager using the `with` statement. + It records the time taken for the code within the `with` block to execute and logs it + along with the provided `name`. + + Args: + name (str): The name of the code block being profiled. This will be included in the log message. + + Yields: + Iterator[None]: An iterator that allows the code within the `with` block to execute. + + Example: + ```python + with profile_function("My Code Block"): + # Code to be profiled + ``` + """ start_time = time.perf_counter_ns() - yield # <-- your code will execute here + yield total_time = time.perf_counter_ns() - start_time logging.info(f"{name}: {total_time / 1000000.0:.4f} ms")