update
This commit is contained in:
19
engine/tests/fixtures/with_imports.py
vendored
Normal file
19
engine/tests/fixtures/with_imports.py
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"""scope=all 的测试 fixture —— 故意 import 一些标准库并实际用它们,
|
||||
让 cProfile 能归因到非用户脚本里的帧。"""
|
||||
import json
|
||||
import time
|
||||
|
||||
|
||||
def payload():
|
||||
# 强制 json.loads / json.dumps 进 cProfile 栈
|
||||
return json.loads(json.dumps({"a": 1, "b": [1, 2, 3]}))
|
||||
|
||||
|
||||
def run():
|
||||
for _ in range(50):
|
||||
payload()
|
||||
# 让 time.sleep / 调度器也进栈 —— 注意 sleep < cProfile tick 的话归不到
|
||||
# 它自己头上,但 time 模块的辅助函数会被经过
|
||||
|
||||
|
||||
run()
|
||||
Reference in New Issue
Block a user