Squash merge dev branch: Implement performance monitoring, auto-approve plugin, and fix various warnings
This commit is contained in:
79
test_performance_simple.py
Normal file
79
test_performance_simple.py
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
简单的性能分析功能测试脚本
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
from core.utils.performance import (
|
||||
timeit,
|
||||
profile,
|
||||
performance_stats
|
||||
)
|
||||
|
||||
|
||||
print("=" * 80)
|
||||
print("性能分析功能测试")
|
||||
print("=" * 80)
|
||||
|
||||
# 重置全局性能统计
|
||||
performance_stats.reset()
|
||||
|
||||
# 测试1: 同步函数的时间测量
|
||||
@timeit
|
||||
def sync_test():
|
||||
"""同步测试函数"""
|
||||
time.sleep(0.1)
|
||||
return "sync done"
|
||||
|
||||
# 测试2: 异步函数的时间测量
|
||||
@timeit
|
||||
async def async_test():
|
||||
"""异步测试函数"""
|
||||
await asyncio.sleep(0.1)
|
||||
return "async done"
|
||||
|
||||
# 异步主函数
|
||||
async def main():
|
||||
# 同步函数测试
|
||||
print("执行同步函数...")
|
||||
sync_result = sync_test()
|
||||
print(f"同步函数结果: {sync_result}")
|
||||
|
||||
# 异步函数测试
|
||||
print("\n执行异步函数...")
|
||||
async_result = await async_test()
|
||||
print(f"异步函数结果: {async_result}")
|
||||
|
||||
# 测试3: 详细性能分析
|
||||
print("\n2. 测试性能分析上下文管理器:")
|
||||
print("=" * 80)
|
||||
|
||||
with profile(enabled=False): # 禁用实际分析以避免输出太多
|
||||
await asyncio.sleep(0.05)
|
||||
print("性能分析上下文管理器测试完成")
|
||||
|
||||
# 测试4: 性能统计报告
|
||||
print("\n3. 测试性能统计报告:")
|
||||
print("=" * 80)
|
||||
|
||||
# 执行多次函数调用
|
||||
for _ in range(3):
|
||||
sync_test()
|
||||
await async_test()
|
||||
|
||||
# 生成并打印性能报告
|
||||
print("\n性能统计报告:")
|
||||
print(performance_stats.report())
|
||||
|
||||
|
||||
# 执行测试
|
||||
print("\n1. 测试时间测量装饰器:")
|
||||
print("=" * 80)
|
||||
|
||||
# 使用 asyncio.run() 执行异步主函数
|
||||
asyncio.run(main())
|
||||
|
||||
print("\n" + "=" * 80)
|
||||
print("所有测试完成!")
|
||||
print("=" * 80)
|
||||
Reference in New Issue
Block a user