fmeval.perf_util

 1import contextlib
 2from timeit import default_timer as timer
 3import logging
 4
 5
 6@contextlib.contextmanager
 7def timed_block(block_name: str, logger: logging.Logger):
 8    """
 9    Measure and log execution time for the code block in the context
10    :param block_name: a string describing the code block
11    :param logger: used to log the execution time
12    """
13    start = timer()
14    try:
15        yield
16    finally:
17        end = timer()
18        logger.info(f"{block_name} took {(end - start):.2f} seconds.")
19        logger.info("===================================================")
@contextlib.contextmanager
def timed_block(block_name: str, logger: logging.Logger):
 7@contextlib.contextmanager
 8def timed_block(block_name: str, logger: logging.Logger):
 9    """
10    Measure and log execution time for the code block in the context
11    :param block_name: a string describing the code block
12    :param logger: used to log the execution time
13    """
14    start = timer()
15    try:
16        yield
17    finally:
18        end = timer()
19        logger.info(f"{block_name} took {(end - start):.2f} seconds.")
20        logger.info("===================================================")

Measure and log execution time for the code block in the context

Parameters
  • block_name: a string describing the code block
  • logger: used to log the execution time