#!/usr/bin/env python
# -*- conding: utf-8 -*-
# author caoyx
#@time :
import time
#函数即变量
def timer(func):
def deco():
start_time = time.time()
func()
stop_time = time.time()
print ("the func run time is %s" % (stop_time-start_time))
return deco
#deco()
@timer
def test():
time.sleep(3)
print ("in the test ")
test()
decorator python 装饰器
最新推荐文章于 2025-08-20 01:02:11 发布
本文介绍了一种使用Python装饰器来测量函数运行时间的方法,通过一个简单的例子展示了如何利用装饰器来增强函数,实现对函数执行时间的精确监控。
343

被折叠的 条评论
为什么被折叠?



