Why does stack.inspect take so long?

63q2o4i02 at sneakemail.com 63q2o4i02 at sneakemail.com
Mon May 15 22:06:18 EDT 2006


Hi, I've written a top-down recursive decent parser for SPICE circuit
descriptions.  For debugging purposes, I wanted each production
rule/function to know what its own name was, so at the beginning of
each rule/function, I make a call to inspect.stack()[0][3] (I think...)
and that fetches the name from someplace.  However, with a bunch of
test text input, this takes ~10 seconds to run.  When I comment out the
inspect.stack() function from each production/function, the program
speeds up to 0.04s, or 250x !!  I loaded up the profiler to see what
was there, and although I don't understand the output entirely, it
looks like the stack frame functions are used in disproportionately
large amounts compared to other often-used functions.  This is a
*recursive* parser, so it's being called a lot even for simple things.
I'm wondering still why there is a 250x speed up when I comment it out.
 Any clues?

thanks
ms




More information about the Python-list mailing list