⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
document
All Projects
document
Overview
Activity
Issues
Spent time
Gantt
Calendar
News
Documents
Wiki
Files
Download (882 Bytes)
Files
» zhuangshiqi.py
UserName LastName
, 03/28/2025 10:55 AM
import
time
import
functools
def
log_execution
(
func
):
"""记录函数执行时间和调用次数的装饰器"""
# 用于存储调用次数
call_count
=
0
@
functools
.
wraps
(
func
)
# 保持原函数的元信息
def
wrapper
(
*
args
,
**
kwargs
):
nonlocal
call_count
call_count
+=
1
# 每次调用时增加计数
# 记录开始时间
start_time
=
time
.
time
()
# 调用原函数,并获取返回值
result
=
func
(
*
args
,
**
kwargs
)
# 记录结束时间
end_time
=
time
.
time
()
execution_time
=
end_time
-
start_time
# 打印日志
print
(
f
"调用
{
func
.
__name__
}
的第
{
call_count
}
次,"
f
"输入参数:
{
args
}
,
{
kwargs
}
, "
f
"返回值:
{
result
}
, "
f
"执行时间:
{
execution_time
:.
4
f
}
秒"
)
return
result
return
wrapper
log_execution
(
2
)
« Previous
1
…
342
343
344
345
346
…
437
Next »
(344-344/437)
Loading...