恋人,
在“IPython”中运行“cProfile”时,我无法让“sort_order”选项工作,这与在系统 shell 中运行等效代码(我已经重定向到一个文件,以便能够看到第一个输出行)。我错过了什么?例如,当运行以下代码时:
%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)
... 其余省略
IMO 等效代码从系统外壳 (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”“层”)。我知道我有一个可行的解决方案,但交互式版本会节省时间,我想了解为什么会有不同。
感谢您的时间和帮助!