我在代码上运行了cProfile,这是输出:
% stats 10
646493 function calls (524209 primitive calls) in 3.606 CPU seconds
Ordered by: cumulative time
List reduced from 260 to 10 due to restriction <10>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 3.606 3.606 <string>:1(<module>)
1 0.007 0.007 3.606 3.606 {execfile}
1 0.068 0.068 3.599 3.599 example.py:7(<module>)
3 0.000 0.000 3.266 1.089 tree.py:1058(parseString)
6698/3 0.068 0.000 3.244 1.081 tree.py:2406(do_parse3)
104813/3 1.084 0.000 3.244 1.081 tree.py:926(_nocache)
2615/3 0.016 0.000 3.243 1.081 tree.py:2679(internal_parse)
3602/14 0.712 0.000 3.239 0.231 tree.py:2531(do_parse2)
13/8 0.000 0.000 3.229 0.404 tree.py:2876(do_parse)
2546/20 0.024 0.000 3.218 0.161 tree.py:1003(parse)从医生那里,
我们定义原语表示调用不是通过递归诱导的
然后,我可以安全地得出结论,我的代码之所以缓慢的原因是:
由于有122284个递归调用,所以最大的递归方法是_nocache.
do_parse3调用都是微不足道的,不能进一步优化。发布于 2011-05-09 08:05:55
,
我可以建议用呼叫图代替吗?为此,我使用Gprof2Dot:
gprof2dot.py -f pstats tmp.pstats区点-Tpng -o tmp.png
http://code.google.com/p/jrfonseca/wiki/Gprof2Dot
http://maxy.homeip.net/misc/gprof2dot_example.png
https://stackoverflow.com/questions/5932462
复制相似问题