3
我跑了CPROFILE我這個代碼輸出,這是輸出:明確從pstats模塊
% 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遞歸調用。
- 最大的遞歸方法是
do_parse3
&_nocache
。 - 原始調用不重要&無法進一步優化。
+1 Grpof2Dot,偉大的工具! – 2011-05-10 08:28:32