Created
October 10, 2024 20:10
-
-
Save rdammkoehler/b3bf2aa1d91386a61f925cac8764ec70 to your computer and use it in GitHub Desktop.
Python Timing Decorator (simple)
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 | |
from datetime import datetime | |
import time | |
def timed(method): | |
def _timed(*args, **kwargs): | |
start_time = time.time() | |
result = method(*args, **kwargs) | |
end_time = time.time() | |
logging.debug( | |
'{0}\t{1!r}\t{2:2.2f} ms\n'.format(datetime.now(), method.__name__, (end_time - start_time) * 1000)) | |
return result | |
return _timed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment