I'm trying to optimize some python code by isolating part of the code into a C++ extension. However, since the code is heavily object-oriented, I'll need to set some attributes as PyObject*. My question is how fast is this compared to pure python code? for example
PyObject* MyClass::doStuff(){ // _a is a PyObject* PyObject* py_attribute = PyObject_GetAttrString(this->_a, "py_attribute"); PyObject* result = PyObject_CallMethod(py_attribute, "do_stuff"); return result; }
vs.
def do_stuff(self):
result = self._a.py_attribute.do_stuff()
return result
I've heard that there's an overhead when doing this, but how fast is it compared to pure python?
Thanks