High Performance Python Extensions: Part 1
crumpington.com
High Performance Python Extensions: Part 1
1–10 of 20 posts
Re: High Performance Python Extensions: Part 1
#2Re: High Performance Python Extensions: Part 1
#3Why not Cython?
Re: High Performance Python Extensions: Part 1
#4Re: High Performance Python Extensions: Part 1
#5Re: High Performance Python Extensions: Part 1
#6One does not necessarily need to get you hands dirty writing c-extensions ( although it can be a good exercise to learn the CPython API ).
In cython, you just need to sprinkle some static types to the inner loops and bump the speed up.
Re: High Performance Python Extensions: Part 1
#7https://gist.github.com/syllog1sm/3dd24cc8b0ad925325e1
It's getting 18,000 steps/second, in the same ballpark as your C code.
I prefer to "write C in Cython", because I find it easier to read than the numpy code. This may be my bias, though --- I've been writing almost nothing but Cython for about two years now.
Btw, if anyone's interested, "cymem" is a small library I have on pip. It's used to tie memory to a Python object's lifetime. All it does is remember what addresses it gave out, and when your Pool is garbage collected, it frees the memory.
Edit: GH fork, with code to compile and run the Cython version: https://github.com/syllog1sm/python-numpy-c-extension-exampl... . I hacked his script quickly.
Re: High Performance Python Extensions: Part 1
#8There are also other approaches like the HOPE jit https://github.com/cosmo-ethz/hope and Theano which is more about expression optimization and compilation: http://deeplearning.net/software/theano/
Re: High Performance Python Extensions: Part 1
#9Here's how I would write this, in Cython using "pure C" arrays: https://gist.github.com/syllog1sm/3dd24cc8b0ad925325e1 It's getting 18,000 steps/second, in the same ballpark as your C code. I prefer to "write C in Cython", because I find it easier to read than the numpy code. This may be my bias, though --- I've been writing almost nothing but Cython for about two years now. Btw, if anyone's interested, "cymem" is a…
Re: High Performance Python Extensions: Part 1
#10If I understand correctly, the `pypy` people strongly encourage the use of `cffi` instead of the CPython API, as the latter is tied too much to CPython and does not permit efficient JITing.