add timeit decorator

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2940 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2005-11-14 22:50:44 +00:00
parent e2a454e31f
commit 99c0382781

View file

@ -38,6 +38,8 @@ def h ():
import warnings
import signal
import os
import sys
import time
def deprecated (func):
@ -131,3 +133,21 @@ def notimplemented (func):
newfunc.__doc__ = func.__doc__
newfunc.__dict__.update(func.__dict__)
return newfunc
def timeit (func, log=sys.stderr):
"""
Print execution time of the function. For quick'n'dirty profiling.
"""
def newfunc (*args, **kwargs):
"""
Execute function and print execution time.
"""
t = time.time()
func(*args, **kwargs)
print >>log, func.__name__, "took %0.2f seconds" % (time.time() - t)
newfunc.__name__ = func.__name__
if func.__doc__ is not None:
newfunc.__doc__ = func.__doc__
newfunc.__dict__.update(func.__dict__)
return newfunc