Cython instead of Pyrex?

Alexander Belchenko bialix at ukr.net
Sun Feb 8 06:32:19 GMT 2009


John Arbash Meinel пишет:
> dhruva wrote:
>> Hello,
>>  Not that I am an expert in this field, I was looking for Pyrex and related tools and came across Cython which claims to be faster than Pyrex. Has it been tried in bzr? Or, is it totally irrelevant?
> 
>> -dhruva
> 
> 
> I believe there are a few issues.
> 
> 1) Pyrex has been around longer, so it is more likely to be available.
> (Last I checked, cython wasn't packaged for ubuntu, for example.)
> 
> 2) Cython *does* help in certain areas, though often they are things
> that you can work around. For example, Cython will recognize that a
> variable is a list, and then compile in the direct PyList_Append()
> function, rather than using the more-generic object interface. (Which
> involves PyObject_Getattr(obj, 'append') and then building up a tuple,
> and a bunch of other overhead.)
> However, if it is performance critical code, you can just use
> PyList_Append yourself, which is compatible with both cython and pyrex,
> and even old versions of pyrex.
> 
> 3) At least some of Cython's optimizations have been backported into
> Pyrex. I'm not sure which ones, but I noticed that with newer versions
> of pyrex, len(foo) is translated differently. In old versions it uses a
> getattr lookup in the builtins dictionary, and in later ones it
> translates the function to PyObject_Length().
> 
> Just to say that *some* of what Cython did to make itself faster has
> already been brought back into Pyrex.
> 
> 4) Cython supports list comprehensions, which would be nice to have, but
> you can always write a for loop. For loops with an integer counter
> (rather than an object) are just as fast. It is just that you can't
> copy&paste the python code.
> 
> Anyway, we talked about it a while back, and basically (1) was the big
> deal-breaker. That we were more likely to have a new version of Pyrex
> available than Cython. That doesn't mean we are stuck going that way,
> but to date, we've done all the inlining to make code work fast with
> Pyrex, so we don't gain much by using cython.

Also Cython generates code for gcc-only. It cannot be compiled with MSVC.




More information about the bazaar mailing list