import time
import logging

logging.basicConfig(level=logging.DEBUG)

def timer(func):
    def inner(*args, **kwargs):
        start = time.time()
        ret = func(*args, **kwargs)
        end = time.time()
        logging.info("time: {:.2f} s".format(end - start))
        return ret

    return inner

@timer
def function():
        print "hello"
function()
[root@tx ~]# python time
hello
INFO:root:time: 0.00 s

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code