473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Embedding performance.

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
1 1446
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Wenning Qiu | last post by:
I am researching issues related to emdedding Python in C++ for a project. My project will be running on an SMP box and requires scalability. However, my test shows that Python threading has very...
0
by: jordi | last post by:
Hi, I'm starting to use Python embedded in a C program. I'm using Python to execute several scripts using as a variables information retrieved for several multithread "agents" written in C. ...
0
by: Julio C?sar Carrascal | last post by:
Hi. I'm interested in learning ModPython to develop a web application. What are my options in terms of embedding python in HTML?. I know there are several products arround but I would like to...
4
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
5
by: Victor Fees | last post by:
I have an XML string in a database that I would like to display using XSLT. All of that works like a champ, but I can't figure out how to embed the XML inside an ASPX page. For example, I have...
1
by: amit | last post by:
Hello, I am currently studying how to embedd python. I am developing a graphical C++ application. My goal is to embedd python script that will control some kind of animation. I have some...
0
by: hq4000 | last post by:
Given AStyleSheet.xsl : <AStyleSheet> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.mytest.mytest2.mytest3.com" version="1.0"> <xsl:output method="xml"...
7
by: Mr. Roboto | last post by:
Folks: I want to embark on a project to add Python (actually, wxPython or PythonWin) to a new Windows app I want to start writing soon. Essentially, I want to take VB6 (or pos Delphi) and...
18
by: Andrew Backer | last post by:
Is it possible to embed a newline constant in a string in the same way as c#? I really don't want to do something like this: ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t)...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.