Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import logging
- logging.basicConfig(level=logging.INFO)
- RANGE = 10000000
- def _time_it(func):
- def wrapper():
- start_time = time.time()
- try:
- func()
- except Exception:
- raise
- finally:
- end_time = time.time()
- total_time = end_time - start_time
- minutes, seconds = divmod(total_time, 60)
- print(f"Function '{func.__name__}' took {int(minutes)} "\
- f"minutes and {seconds:.2f} seconds to complete.")
- return wrapper
- @_time_it
- def with_formatting():
- for index in range(RANGE):
- logging.debug(f"Script: {__name__} formatting index {index}")
- @_time_it
- def without_formatting():
- for index in range(RANGE):
- logging.debug("Script: %s formatting index %d", __name__, index)
- with_formatting()
- without_formatting()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement