Skip to content

Instantly share code, notes, and snippets.

@signed0
Created February 1, 2012 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save signed0/1718878 to your computer and use it in GitHub Desktop.
Save signed0/1718878 to your computer and use it in GitHub Desktop.
Execution time decorator
'''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