愛好者,的Python VS IPython的CPROFILE SORT_ORDER
當「IPython的」我不能得到的「排序順序」選項的工作,而相比之下,在系統shell中運行的等價代碼運行「CPROFILE」(我已被重定向到一個文件,能夠看到輸出的第一行)。我錯過了什麼? 例如運行下面的代碼時:
%run -m cProfile -s cumulative myscript.py
給我下面的輸出(排序:標準名稱):
9885548 function calls (9856804 primitive calls) in 17.054 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 <string>:1(DeprecatedOption)
1 0.000 0.000 0.000 0.000 <string>:1(RegisteredOption)
6 0.000 0.000 0.001 0.000 <string>:1(non_reentrant)
1 0.000 0.000 0.000 0.000 <string>:2(<module>)
32 0.000 0.000 0.000 0.000 <string>:8(__new__)
1 0.000 0.000 0.000 0.000 ImageFilter.py:106(MinFilter)
1 0.000 0.000 0.000 0.000 ImageFilter.py:122(MaxFilter)
1 0.000 0.000 0.000 0.000 ImageFilter.py:140(ModeFilter)
...其餘省略
海事組織等效代碼從系統運行外殼(Win7的):
python -m cProfile -s cumulative myscript.py > outputfile.txt
給了我下面的有序輸出:
9997772 function calls (9966740 primitive calls) in 17.522 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.116 0.116 17.531 17.531 reprep.py:1(<module>)
6 0.077 0.013 11.700 1.950 reprep.py:837(add_biorep2treatment)
9758 0.081 0.000 6.927 0.001 ops.py:538(wrapper)
33592 0.100 0.000 4.209 0.000 frame.py:1635(__getitem__)
23918 0.010 0.000 3.834 0.000 common.py:111(isnull)
23918 0.041 0.000 3.823 0.000 common.py:128(_isnull_new)
...其餘省略
我也注意到,有在函數調用的數量不同。爲什麼?我正在運行Python 2.7.6 64位(來自Enthought)並確保兩個執行都使用完全相同版本的Python(儘管當然第一個有一個額外的「IPython」「圖層」) 。 我知道我有一個工作解決方案,但交互式版本將是一個節省時間,我想了解爲什麼有差異。
謝謝你的時間和幫助!
你使用'%run'還是'%prun'? – Drewness
如果他剖析Python文件運行的腳本,然後'%prun'不會在這裏工作,我不認爲。 –