python计算代码运行时间的装饰器

import time


def cal_time(func):
    def wrapper(*args, **kwargs):
        t1 = time.time()
        result = func(*args, **kwargs)
        t2 = time.time()
        print("%s running time: %s secs." % (func.__name__, t2-t1))
        return result
    return wrapper

 

posted @ 2018-12-15 13:32  小学弟-  阅读(387)  评论(0编辑  收藏  举报