Aaron DeVore wrote:
> I'm working on a Cython-based library where I need to check the type/class
> of objects very, very often. Depending on the data that is fed in and the
> calls the developer makes I may have to do hundreds of thousands of checks.
> Because of that any significant difference between PyObject_IsInstance and
> PyObject_TypeCheck is important.

[...]

Do you want to check for builtin types like PyString, PyUnicode etc. or 
subclasses? Python has super fast checks for builtin types, for example 
PyString_Check(obj) or PyString_CheckExact(obj).

PyObject_TypeCheck is a macro while PyObject_IsInstance is a recursive 
function that does much more work than PyObject_TypeCheck. Therefore 
PyObject_TypeCheck should be a bit faster than PyObject_IsInstance. By 
the way the latter is invoked by isinstance(), too.

Christian

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to