Page 212 - CodePilot V5.0 C8
P. 212
Step 3 Compile the Cython Code
In the terminal (in the same folder), run:
This will create a compiled .pyd file.
Step 4 Create a math.py file to use the Compiled Module in Python.
Now, run the math.py file by pressing the F5 key. The result is shown as follows:
COMPARING PURE PYTHON VS. CYTHON
Feature Pure Python Cython
Execution Speed Slower (interpreted) Faster (compiled to C)
Syntax Simple and clean Similar to Python with optional type hints
Performance Optimisation Limited High (especially with typed variables)
Setup Requirement None Requires Cichon and C compiler
C/C++ Integration Difficult Easy and native
NumPy Performance Slower in loops Optimised with typed memoryviews
Use Case General scripting, web apps Scientific computing, heavy computation
Learning Curve Very low Moderate (especially for C-style types)
Compilation Step Not required Required (e.g., via setup.py)
Interoperability Pure Python ecosystem Compatible with Python and C libraries
210
CodePilot (V5.0)-VIII

