This is my usage of decorators in Python to measure an elapsed time of
a method running in a class.
It's very convenience to compare several algorithms.
--DongWoo
-------
def Timer(f):
def measureTime(self, *args, **kargs):
print "Start..."
start = time.time()
ret = f(self, *args, **kargs)
elapsed = time.time()-start
print "End..... %.2f sec" % elapsed
return ret
return measureTime
class A(BASE):
def __init__(self, a, b, c):
@Timer
def run(self):
......
class B(BASE):
def __init__(self, a, b, c, d):
@Timer
def run(self):
......