相关疑难解决方法(0)

将cProfile结果保存到可读的外部文件中

我正在cProfile尝试尝试分析我的代码:

pr = cProfile.Profile()
pr.enable()
my_func()   # the code I want to profile
pr.disable()
pr.print_stats()
Run Code Online (Sandbox Code Playgroud)

但是,结果太长,无法在Spyder终端中完全显示(看不到运行时间最长的函数调用...)。我也尝试使用保存结果

 cProfile.run('my_func()','profile_results')
Run Code Online (Sandbox Code Playgroud)

但是输出文件的格式不是人类可读的格式(尝试使用带.txt后缀和不带后缀)。

所以我的问题是如何将分析结果保存到人类可读的外部文件中(例如以.txt正确显示所有单词的格式)?

python text profiling cprofile python-3.x

6
推荐指数
4
解决办法
3928
查看次数

标签 统计

cprofile ×1

profiling ×1

python ×1

python-3.x ×1

text ×1