25

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

3
  • Are you using profile.run() to run the profiler? Then <string>:1 refers to the first line of the statement string you passed to this function. If you are calling the profiler in a different way, please specify. Commented May 11, 2011 at 12:47
  • @Sven Marnach: Good point, I've added this info to the question. Commented May 11, 2011 at 12:49
  • 1
    Assuming you're asking because you want higher performance, try this. Commented May 11, 2011 at 13:30

1 Answer 1

26

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.

Sign up to request clarification or add additional context in comments.

3 Comments

but what if the largest tottime is <string>:1(<module>)?
<string>:1(<module>) is top-level code in the entry-point Python script invoked. So if all your code is top-level in "foo.py" and you do python foo.py, then you'll see a high tottime for <string>:1(<module>). By "top-level", I mean not inside any function definition - just run directly.
if I order the %prun output by tottime I have 8.9 seconds (of 9.6 overall) in <string>:1(<module>). The next entry is 0.2 s and then it decreases quickly. What happens in the top entry?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.