愛好家、
「IPython」で「cProfile」を実行すると、システムシェルで同等のコードを実行するのとは対照的に、「sort_order」オプションが機能しません(ファイルにリダイレクトして、最初の出力の行)。私は何が欠けていますか?たとえば、次のコードを実行する場合:
%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) から実行される IMO の同等のコード:
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」「レイヤー」があります)。実用的なソリューションがあることはわかっていますが、インタラクティブ バージョンの方が時間を節約できるので、違いがある理由を理解したいと思います。
お時間をいただき、ありがとうございました!!