Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 140 - 2629_Devagiri_C-8
P. 140

    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

                       138
                            Premium Edition-VIII

| 135 136 137 138 139 140 141 142 143 144 145 |