Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python与IPython cProfile排序顺序_Python_Sorting_Ipython_Cprofile - Fatal编程技术网

Python与IPython cProfile排序顺序

Python与IPython cProfile排序顺序,python,sorting,ipython,cprofile,Python,Sorting,Ipython,Cprofile,情人们 在“IPython”中运行“cProfile”时,我无法让“sort_order”选项工作,这与在系统shell中运行等效代码(我已将其重定向到文件,以便能够看到输出的第一行)形成对比。我错过了什么? 例如,运行以下代码时: %run -m cProfile -s cumulative myscript.py 提供以下输出(按:标准名称排序): 提供以下已排序的输出: 9997772 function calls (9966740 primitive calls) in 17.522

情人们

在“IPython”中运行“cProfile”时,我无法让“sort_order”选项工作,这与在系统shell中运行等效代码(我已将其重定向到文件,以便能够看到输出的第一行)形成对比。我错过了什么? 例如,运行以下代码时:

%run -m cProfile -s cumulative myscript.py
提供以下输出(按:标准名称排序):

提供以下已排序的输出:

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)
9997772个函数调用(9966740个基本调用)在17.522秒内完成
排序人:累计时间
ncalls tottime percall cumtime percall文件名:lineno(函数)
1 0.116 0.116 17.531 17.531报告副本:1()
6 0.077 0.013 11.700 1.950重复py:837(添加处理)
9758 0.081 0.000 6.927 0.001操作py:538(包装器)
335920.100 0.000 4.209 0.000帧。py:1635
239180.010 0.000 3.834 0.000通用。py:111(isnull)
23918 0.041 0.000 3.823 0.000通用。py:128(\u isnull\u new)
。。。其余省略

我还注意到函数调用的数量有所不同。为什么?

我正在运行Python2.7.6 64位(来自Enthound),并确保两次执行都使用了完全相同的Python版本(当然,第一次执行还有一个额外的“IPython”层)。 我知道我有一个可行的解决方案,但交互式版本会节省时间,我想了解为什么会有不同


谢谢你的时间和帮助

%run
有一些评测选项。实际上来自
%prun
的文档:

如果要在探查器的控制下运行完整的程序,请使用
%run-p[prof_opts]filename.py[args to program]
其中prof_opts 包含此处所述的探查器特定选项


可能是更好的方法。

您使用的是
%run
还是
%prun
?如果他将python文件作为脚本运行,那么
%prun
在这里不起作用,我认为。
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)