#! /usr/bin/env python # -*- coding:utf-8 -*- import time def timer(fun): def deco(*args, **kwargs): start_time = time.time() fun(*args, **kwargs) stop_time = time.time() print("fun cost time:%s" % (stop_time - start_time)) return deco @timer # test1 = timer(test1) def test1(): time.sleep(1) print("this is test1") @timer def test2(name): time.sleep(1) print("this is test2 ", name) test1() test2("leif")
参考http://egon09.blog.51cto.com/9161406/1836763