On Sep 22, 2008, at 2:46 AM, Christian Heimes wrote: > 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.
Note also that PyObject_TypeCheck checks for types, and normal python classes aren't types. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
