what does "execfile" mean within profiler output and why does it not have a attached line number

Robert Kern robert.kern at gmail.com
Sat Apr 4 20:59:24 EDT 2009


On 2009-04-04 18:56, Rahul wrote:
> "profile" tells me that most of my runtime was spent in just one part (1.28
> sec cumulatively out of 1.29 secs. But what is "execfile"? I don't see this
> as a function call with my python code. Also what's the 0 in the snippet:
> ":0(execfile)"? Isn't there supposed to be a line-number?

It's a builtin function, so it has no filename or line number.

execfile is a function that reads a Python file and executes its code. This is 
almost certainly the execfile call from profile.py itself that is running your 
code. Ignore it.

> Looking up "execfile" in the python manual leads me to "exec": "This
> statement supports dynamic execution of Python code."
>
> But that seems pretty generic; how can I now try figuring out which part of
> my python file is the bottleneck?

To quickly find your hotspots, start by sorting by 'time' (that would be 
displayed as the 'tottime' column in the human-readable output). That tells you 
how much time is spent in each function itself, excluding the time it spends 
calling out to other functions. For example, per the docs under "Instant User’s 
Manual" (which you might want to spend a little more time with):

   p.sort_stats('time').print_stats(10)

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list