Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The biggest speed benefit comes from using C primitive types instead of Python objects, for example machine integers instead of Python / Sage integer objects. Of course thats a pretty small list of types.

You can also declare any Cython cdef class, but that mostly saves you from having to cast the Python object to the cdef class all the time. Not so much speed benefit.

Python lists are still hash tables containing Python objects even if you declare them as cdef list foo. In particuar, it is not possible to have a memory-contiguous array of a particular C datatype that way. You shoud use C arrays or C++ std::vector if you need arrays of a fixed C datatype.

Note that your question smells of premature optimization. If you haven't benchmarked your Python implementation yet then don't bother.