Skip to content

Instantly share code, notes, and snippets.

@mehd-io
Created August 22, 2024 12:31
Show Gist options
  • Select an option

  • Save mehd-io/f5df9ecd438366884801c78bf0f264cd to your computer and use it in GitHub Desktop.

Select an option

Save mehd-io/f5df9ecd438366884801c78bf0f264cd to your computer and use it in GitHub Desktop.

Revisions

  1. mehd-io revised this gist Aug 22, 2024. No changes.
  2. mehd-io renamed this gist Aug 22, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. mehd-io created this gist Aug 22, 2024.
    31 changes: 31 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    import logging
    from datetime import datetime
    import functools

    # Setting up logging
    logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger(__name__)

    def measure_time(func):
    @functools.wraps(func)
    def wrapper_measure_time(*args, **kwargs):
    start_time = datetime.now()
    result = func(*args, **kwargs)
    end_time = datetime.now()
    elapsed = (end_time - start_time).total_seconds()
    logger.info(
    f"{func.__name__} function completed in {int(elapsed // 60)} minutes "
    f"and {elapsed % 60:.2f} seconds."
    )
    return result

    return wrapper_measure_time

    @measure_time
    def pipeline():
    # Do stuff here, it will be timed
    logger.info("Pipeline started.")


    if __name__ == "__main__":
    pipeline()