Created
July 22, 2010 17:59
-
-
Save justinabrahms/486336 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
# from __future__ import with_statement # py2.5 | |
from contextlib import contextmanager | |
import logging | |
@contextmanager | |
def log_execution_time(log_msg): | |
""" | |
Context manager which logs the time spent doing a | |
particular activity. | |
Usage: | |
:: | |
with log_execution_time("get response"): | |
self.login() | |
response = self.client.post(url, params) | |
self.assertRedirects(response, '/') | |
# Logs (to debug) | |
# get response: 0.10758805275 | |
""" | |
start_time = time.time() | |
yield | |
logging.debug("%s: %s" % (log_msg, time.time() - start_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment