Calling a function is faster than not calling it?

Skip Montanaro skip.montanaro at gmail.com
Mon May 11 10:12:10 EDT 2015


On Mon, May 11, 2015 at 4:50 AM, BartC <bc at freeuk.com> wrote:

> You just seem surprised that using eval() to do this is slower than a
> direct call.


Well, it is surprising. Most uses of eval() are to evaluate Python
expressions in string form. That I expect to be quite slow, given the
parsing+byte compilation overhead. I wouldn't expect eval()ing a code
object to be all that different than calling the function containing the
code object.

My guess (without looking in ceval.c) is that the code path through the VM
has been tweaked heavily over the years to try and speed it up. Except for
places where that path overlaps with the path for eval(code_object), I
doubt any attention has been paid to speeding up eval. I could certainly be
way off-base here. Perhaps the path taken through the interpreter for
eval(code_object) is more-or-less a subset of the path taken for a simple
function call.

Skip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150511/7a6c961a/attachment.html>


More information about the Python-list mailing list