现在的位置: 首页 > 综合 > 正文

python profile 使用

2013年08月23日 ⁄ 综合 ⁄ 共 507字 ⁄ 字号 评论关闭

profile 主要是得到每个函数的使用时间,从而为优化提供一个数据支持

我的pc 环境 ubuntu 11.04 python2.7
如果按照 参考2 中 直接使用报错,官方文档建议使用cProfile

import cProfile
cProfile.run('foo()', 'fooprof')

但是还是会报错 ,说 pstats 找不到,但是直接import pstats 也失败 。

解决方案:

sudo apt-get install python-profiler
import cProfile
cProfile.run("testDict()")
import pstats
p = pstats.Stats("prof.txt")
p.sort_stats("time").print_stats()

参考:

1:http://docs.python.org/2/library/profile.html

2:http://blog.csdn.net/lanphaday/article/details/1483728

原始博客地址:http://www.fuxiang90.com/2012/12/python-profile-%E4%BD%BF%E7%94%A8/

抱歉!评论已关闭.