import cProfile,pstats
def product(x,y):
return x*y
cProfile.run('product(1, 2)','result.txt')#将结果写入文件result.txt
p = pstats.Stats('result.txt')
p.strip_dirs().sort_stats(-1).print_stats() # strip_dirs:从所有模块名中去掉无关的路径信息
p.strip_dirs().sort_stats("name").print_stats() # sort_stats():把打印信息按照标准的module/name/line字符串进行排序
p.strip_dirs().sort_stats("cumulative").print_stats(3) # print_stats():打印出所有分析信息
**另外检查源代码存在的问题 pylint 模块名**
程序性能分析
最新推荐文章于 2023-07-16 17:50:30 发布