Quick example of cythonizing a function. Shouldn't be taken as a model implementation - just for my own reference.
Example taken from the official Cython tutorial.
Everything needed is in primes.pyx
.
The corresponding pure Python function is located in primes_py.py
.
There are two ways to run.
- Compiling automatically using
pyximport
- Manually building the extension
Simply run:
$ python test_quick.py
Pure Python version average 0.9142 +/- 0.04769 seconds
Cython version average 0.0276 +/- 0.00300 seconds
Cython speed up: 33.120
$ sh setup.sh
$ python test.py
Cython version average 1.0102 +/- 0.08426 seconds
Cython version average 0.0271 +/- 0.00164 seconds
Cython speed up: 37.217
$ sh reset.sh