performance question when using embedding/extending
Eibl Christian Object Vision
Christian.Eibl-ObjectVision at kst.siemens.de
Mon Jan 31 08:06:21 EST 2000
hi,
i need to call a python function from my c++ app and this python function in
turn
accesses an instanciated c++ object (i pass the pointer to the object as a
parameter).
in the python function i have approx. 20-30 calls to the object (simple
member accessing).
the goal:
provide a scripting interface for computation of certain parameters
depending on the
state of a changing object...
when i'm doing a simple performance test (just calling the function 100.000
times in c++)
it turns out that on my 300MHZ PII the function is called 32.000 times per
second if
i don't access any attributes via python and it goes down to 900 times per
second if
i place 30 access calls in the python function.
i "quantified" the application an see that almost all the cpu-time is used
in "PyEval_CallObject".
the application i'm building needs at least 10-times the performance it has
now...
my question:
- is this just the (slow) way it is ?
- is there a faster way to use embedding/extending (details see below) ?
- is python not suitable for this task (the old system was also an
interpreter, but specifically
written for this task) ?
the details::
i'm using the following code in my app to call a python function in a
module:
<snip>
_pythonCaller_p->runWithObject( "i", &finalResult, somePtr_p,
"_SomeClass_p" )
</snip>
the "runWithObject" method is defined as follows:
NOTE: i'm using SWIG with shadow classes to generate python interfaces for
my C++ classes!
<snip>
bool PythonCaller::runWithObject( char* resultFormat, void* result_p, void*
pyObj_p, char* pyType)
{
PyObject* func_p = 0;
PyObject* args_p = 0;
PyObject* resu_p = 0;
if( _doReload ) {
func_p = loadAttribute( _moduleName, _functionName );
}
else {
func_p = _pyFunction;
}
if( func_p==0 ) {
return false;
}
char aTmp[256];
SWIG_MakePtr( aTmp, pyObj_p, pyType );
args_p = Py_BuildValue( "(s)", aTmp );
if( args_p==0 ) {
return false;
}
resu_p = PyEval_CallObject( func_p, args_p );
if( resu_p==0 ) PyErr_Print();
if( _doReload ) {
Py_DECREF(func_p);
}
Py_DECREF(args_p);
</snip>
the python function called with this code is defined as follows:
import Mc
import Mcc
def calcAttrFinalCoding(mp) :
mpi = Mc.MailpiecePtr( mp )
mpc = mpi.fetch()
if mpc.getPbrInfoStatus() == Mcc.barcodeOk :
return Mcc.attrCodBc
if mpi.getBvInfoStatus() == Mcc.barcodeOk :
return Mcc.attrCodBc
if mpi.getPbrInfoStatus() == Mcc.barcodeOk :
return Mcc.attrCodBc
if mpi.getBvInfoStatus() == Mcc.barcodeOk :
return Mcc.attrCodBc
if mpi.getPbrInfoStatus() == Mcc.barcodeOk :
return Mcc.attrCodBc
return 1
thanx for any help!
Chris
--
Christian Eibl
Object Vision Software AG, München
Christian.Eibl at ovsag.de | www.ovsag.de
mobile: +49.171.7623844 or +43.676.3060031
pgp-fingerprint: D681 0321 30BE FA99 AD03
FBE7 38C5 E788 2846 25DB
More information about the Python-list
mailing list