diff --git a/linkcheck/decorators.py b/linkcheck/decorators.py index dd76a403..3e6be425 100644 --- a/linkcheck/decorators.py +++ b/linkcheck/decorators.py @@ -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