[Pyrex] possible bug in Pyrex

Robert Bradshaw robertwb at math.washington.edu
Fri Feb 26 01:36:01 CET 2010


On Feb 25, 2010, at 3:29 PM, Greg Ewing wrote:

> Stefan Behnel wrote:
>
>> As a general rule of thumb, the code generated by Cython is quite a  
>> bit
>> longer and substantially faster than the corresponding Pyrex code.
>
> Be careful you're not comparing apples with oranges here,
> though. Pyrex is capable of generating quite efficient code
> for many things, it's just not as automatic as Cython.

Yes, for example, both can generate near optimal code with heavy use  
of the Python/C API. One of Cython's goals is that users no need to  
know this API to generate optimal code (or at least as close as we can  
get). There are other things, such as argument unpacking, that can't  
be as easily controlled by the user.

> For example, I gather that Cython will generate a test
> for a list object and index it using list-specific calls
> in that case.
>
> Recent versions of Pyrex will also use list-specific calls,
> but only if you declare it as a list. Theoretically this
> should be even faster, because there is no run-time test
> involved.


If an object is declared as a list, no run-time test will be generated  
in Cython either. There is a slight performance penalty for, say,  
indexing into a non-list with a cdef int, but it is relatively small  
and yields large gains for the common case of indexing into a list.

- Robert




More information about the Pyrex mailing list