Python's profile module: :1(?)

2019-04-18 03:17发布

问题:

I am using Python's (v2.4) profile module to profile a numpy script, and the following entry appears to account for the bulk of the execution time:

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

Unfortunately, its appearance makes it hard to Google.

How do I go about figuring out what this is exactly?

edit The profiler is run from the shell as follows: python -m profile -s cumulative script.py

回答1:

Ignore this line. It is an artifact of how the profiler is implemented. It is not telling you anything useful. Look at the "tottime" value for it: 0.000. "tottime" is the amount of time spent executing "<string>:1(?)" excluding time spent executing children of it. So, no time is spent here. "cumtime" and "percall" are large because they include time spent in children. See http://docs.python.org/library/profile.html#cProfile.run for more details.