190. Cython for Performance
1
Basic Cython Speedup
# Cython file (example1.pyx)
def add(int a, int b):
return a + bfrom setuptools import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize("example1.pyx")
)python setup.py build_ext --inplacefrom example1 import add
print(add(10, 20)) # Output: 302
Using cdef for Fast Loops
cdef for Fast Loops3
Using nogil for Parallelism
nogil for Parallelism4
Using Cython with NumPy
5
Calling External C Functions
Last updated