By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,172 Members | 727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,172 IT Pros & Developers. It's quick & easy.

Embedding performance.

P: n/a
Hello,

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

PyEval_EvalCode()
PyRun_SimpleFile()
PyObject_CallObject()

Thanks
Amit
Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
amit wrote:
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.:)

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.