Python的配置文件模块:<string>:1(?)

NPE*_*NPE 22 python profile profiler profiling

我使用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(?)
Run Code Online (Sandbox Code Playgroud)

不幸的是,它的外观让谷歌很难.

我该如何弄清楚这究竟是什么?

编辑分析器从shell运行,如下所示:python -m profile -s cumulative script.py

Jea*_*one 22

忽略这一行.它是如何实现探查器的工件.它没有告诉你任何有用的东西.查看它的"tottime"值:0.000."tottime"是执行"<string>:1(?)"所花费的时间,不包括执行它的子项所花费的时间.所以,这里没有时间."cumtime"和"percall"很大,因为它们包括在儿童中度过的时间.有关详细信息,请参阅http://docs.python.org/library/profile.html#cProfile.run.

  • `<string>:1(<module>)`是调用的入口点Python脚本中的顶级代码.因此,如果您的所有代码都是"foo.py"中的顶级代码并且您执行`python foo.py`,那么您将看到`<string>:1(<module>)`的高总时间.通过"顶级",我的意思是不在任何函数定义中 - 只是直接运行. (5认同)
  • 但如果*最大*tottime是`<string>:1(<module>)`怎么办? (2认同)