Python--装饰器

import time

         #import funct     # define decorator# record time1  #call f  and excute  f  then store the result in 'r'
          #  reocond end time
          #compute time2-time1
          ##return result
     #return decorator


def performance(f):
    def fn(*args):
        t1=time.time()
        r=f(*args)
        t2=time.time()
        print f.__name__+ '   '+str(t2-t1)
        return r
    return fn
@performance
def factorial(n):
    return reduce(lambda x,y: x*y, range(1, n+1))

print factorial(10)
posted @ 2016-03-08 22:29  Salaku  阅读(116)  评论(0编辑  收藏  举报