【问题标题】:Python's profile module: <string>:1(?)Python 的配置文件模块:<string>:1(?)
【发布时间】:2011-08-23 06:37:30
【问题描述】:

我正在使用 Python 的 (v2.4) profile 模块来分析 numpy 脚本,以下条目似乎占了执行时间的大部分:

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
 256/1    0.000    0.000    7.710    7.710 <string>:1(?)

不幸的是,它的外观让 Google 很难。

我该如何弄清楚这到底是什么?

edit 探查器从 shell 运行如下:python -m profile -s cumulative script.py

【问题讨论】:

  • 您是否使用profile.run() 来运行分析器?然后&lt;string&gt;:1 引用您传递给此函数的语句字符串的第一行。如果您以不同的方式调用探查器,请指定。
  • @Sven Marnach:很好,我已将此信息添加到问题中。
  • 假设您询问是因为您想要更高的性能,try this

标签: python profiling profiler profile


【解决方案1】:

忽略此行。它是分析器如何实现的工件。它没有告诉你任何有用的东西。查看它的“tottime”值:0.000。 “tottime”是执行“:1(?)”所花费的时间量,不包括执行它的子项所花费的时间。所以,没有时间花在这里。 “cumtime”和“percall”很大,因为它们包括在儿童身上花费的时间。详情请见http://docs.python.org/library/profile.html#cProfile.run

【讨论】:

  • 但是如果 最大 tottime 是&lt;string&gt;:1(&lt;module&gt;)呢?
  • &lt;string&gt;:1(&lt;module&gt;) 是调用的入口点 Python 脚本中的顶级代码。因此,如果您的所有代码都是“foo.py”中的顶级代码并且您执行python foo.py,那么您将看到&lt;string&gt;:1(&lt;module&gt;) 的总时间很高。 “顶级”是指不在任何函数定义中 - 直接运行。
猜你喜欢
  • 2019-05-18
  • 1970-01-01
  • 1970-01-01
  • 2016-05-21
  • 1970-01-01
  • 1970-01-01
  • 2014-06-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多