Cython Speed Boost vs. Usability
- by zubin71
I just came across Cython, while I was looking out for ways to optimize Python code. I read various posts on stackoverflow, the python wiki and read the article "General Rules for Optimization".
Cython is something which grasps my interest the most; instead of writing C-code for yourself, you can choose to have other datatypes in your python code itself.
Here is a silly test i tried,
#!/usr/bin/python
# test.pyx
def test(value):
for i in xrange(value):
i**2
if(i==1000000):
print i
test(10000001)
$ time python test.pyx
real 0m16.774s
user 0m16.745s
sys 0m0.024s
$ time cython test.pyx
real 0m0.513s
user 0m0.196s
sys 0m0.052s
Now, honestly, i`m dumbfounded. The code which I have used here is pure python code, and all I have changed is the interpreter. In this case, if cython is this good, then why do people still use the traditional Python interpretor? Are there any reliability issues for Cython?