mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-19 20:01:53 +00:00
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:
parent
e2a454e31f
commit
99c0382781
1 changed files with 20 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue