Created
December 8, 2021 13:52
-
-
Save maddrum/c135e46bfd5cabf63915391823e1638b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import time | |
logger = logging.getLogger('MyLogger') | |
def measure_run_time(func): | |
def wrapper(*args, **kwargs): | |
total_start_time = time.time_ns() | |
cpu_start_time = time.process_time_ns() | |
result = func(*args, **kwargs) | |
cpu_elapsed_time = int((time.process_time_ns() - cpu_start_time) / 1_000_000) | |
total_time = int((time.time_ns() - total_start_time) / 1_000_000) | |
logger.info(f'[INFO][MEASURE] Function <{func.__name__}> ran for: \n' | |
f' CPU RUNTIME: {cpu_elapsed_time if cpu_elapsed_time > 1 else "< 1"} ms\n' | |
f' TOTAL RUNTIME: {total_time if total_time > 1 else "< 1"} ms \n') | |
return result | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment