Cython - Python at the Speed of C - Printable Version +- Makestation (https://makestation.net) +-- Forum: Technical Arts (https://makestation.net/forumdisplay.php?fid=45) +--- Forum: Software (https://makestation.net/forumdisplay.php?fid=104) +--- Thread: Cython - Python at the Speed of C (/showthread.php?tid=2889) |
Cython - Python at the Speed of C - Darth-Apple - April 11th, 2020 I use Python almost religiously for anything I can get away with. It's honestly *almost* the perfect language. It's easy to write and read (and clean and concise), works on any platform without compiling specifically, has libraries that are perfect for almost anything, and is installed (or easy to install) almost everywhere. The problem with Python is that, boy oh boy, if it isn't slow... And I do a lot of scientific computing with it. It's not acceptable to spend 5 seconds just to rotate one image. So I found Cython. It's one of numerous attempts to make Python significantly faster. Unlike some of the other options, Cython somewhat requires some custom modifications to the underlying code (namely declaring C data types). This is not required. It will compile without a hitch if you forget them, so it's easy to retrofit old code. However, you throw away a lot of the performance benefits if you don't declare the types. I find that it's quite a bit faster than PyPy (another good alternative to the standard Python interpreter that uses just-in-time compilation). Cython is almost a language of its own because it requires certain modifications, but it's literally the ease of Python with the speed of C, and I don't think you can get much better than that. The only downside? You have to compile for every architecture... |