SWIG vs Pyrex vs Cython -- a quicky question

John Arbash Meinel john at arbash-meinel.com
Mon Sep 21 15:44:09 BST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

INADA Naoki wrote:
> Cython +1
> 
> Cython is more powerful than Pyrex.
> C code generated by Cython is more readable than one generated by SWIG.

Sure, though neither Cython or Pyrex is super "readable".

Cython generates C code that includes the Python code as comments, which
can help a lot.

I think Jelmer has a point that you should probably use whatever you are
the most comfortable with :).

Personally, I really like Cython/Pyrex (0.9.8+). You get some nice
things, like being able to have a 'class', and exceptions with
tracebacks. I think it leads to 'safer' wrappers around C calls, because
the compile step generates all of the return code checking for you.

It also lets you write as close to the Python layer that you would like,
and then optimize only the little bits that actually need it.

I've done some work in writing a raw C extension now, because I felt it
was merited. And I have to say, there is just a lot more manual
bookkeeping. You have to define the function at the top, then add it to
the members list. Then manually implement argument parsing, including
whatever complexity if you want to support "*args" or "**kwargs", etc.
You can do it, but Cython makes it trivial to do so.

Now *if* you are only wanting to call existing code (since you are doing
testing), I would probably say that ctypes would be the next best bet.
But if you have to rewrite things to make it into a lib to be loaded, I
would probably go with Cython.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkq3kTkACgkQJdeBCYSNAAMU5QCfSzEVZIynrTYZS1YxZzWKthuV
U/MAoNIW/RqBm2U/HEn3jYyUPBdNnnU+
=4WJ+
-----END PGP SIGNATURE-----



More information about the bazaar mailing list