Created
February 1, 2012 19:45
-
-
Save signed0/1718878 to your computer and use it in GitHub Desktop.
Execution time decorator
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 http://www.daniweb.com/software-development/python/code/216610 | |
Modified to use logging instead of print statments | |
Usage: | |
@log_time | |
def my_function(): | |
pass | |
''' | |
import logging | |
import time | |
def log_time(func): | |
def wrapper(*args, **kwargs): | |
t1 = time.time() | |
res = func(*args, **kwargs) | |
t2 = time.time() | |
logging.info('%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0)) | |
return res | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment