Embedding performance.

A

amit

Hello,

Is there any kind of performance differences to the different ways of
embedding python?

PyEval_EvalCode()
PyRun_SimpleFile()
PyObject_CallObject()

Thanks
Amit
 
K

k33rni

amit said:
Is there any kind of performance differences to the different ways of
embedding python?
PyEval_EvalCode()
PyRun_SimpleFile()
PyObject_CallObject()

AFAIK, these are only different wrappers, while you're generally
getting at the same functionality. I assume you're somewhat familiar
with the Python API. What you're saving using the third one is parsing
and compiling time, since the other two functions do it every time
they're called, I believe. With PyObject_CallObject() you already have
the PyObject, so it just goes straight to the interpreter core, and
does not do any parsing and compiling. That said, you have to get the
object from somewhere first, possibly using the other two :), which may
not apply if you're calling something embedded (that is, written in C).


A quick look in the Python sources brings up the following:
PyRun_SimpleFile: adds __main__. sets __file__. looks for .pyc or .pyo
files, loads the code object from them, or parses text, and finally
calls PyEval_EvalCode with the code object. So there, you have the
overhead.
PyObject_CallObject: goes through some redirection to PyObject_Call,
which calls obj->ob_type->tp_call directly.
PyEval_EvalCode: checks for globals, checks for arguments, creates a
frame with all the necessary stuff, checks for generators, calls
PyEval_EvalFrame() which does all the dirty running of python code.

So there, the least overhead seems to be in CallObject. Don't treat
this as an authoritative answer, though.:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,308
Members
47,955
Latest member
DarciAntho

Latest Threads

Top