visit
The simplicity of python has made even young kids fall in love with
programming. Python is simple, expressive, concise, and offers English-like
syntax, but it is interpreted language and hence a bit slow.
To overcome the slowness of python, developers have created multiple
different compilers to compile python either to other programming languages, to machine code, or to do Just in Time compilation. Some of the popular python compilers include Cython, Nuitka, Brython, PyPy, and Iron Python.
Let us start with the very basics!
Python is a programming language. It is not a compiler or interpreter in itself. Any improvements in Python language specifications or new features would result in nothing till the time those are incorporated in the interpreters or compilers.Given that it is the default implementation of Python, whenever Python is
upgraded with new features, language developers upgrade the CPython version as well and include it in the distribution that you download to set up Python on your machine. So, Python and CPython are different yet can be used together. They can work hand in hand and are upgraded together.
is a separate compiler that can understand both Python and C
specifications. It is more like a superset of Python compiler and allows you to work with Python and C together in a single project.
How does this help? Alright, so, Cython compiles the hybrid python and C
code into a very efficient C program which in turn can be compiled to the
machine code using C compilers.
Given the speed gains we get using Cython it is used heavily to develop
python extension modules. Many popular python modules like SciPy are written in Cython itself.
Just to clarify a bit more, the mixed programs that you write in C and
Python can be termed as a new programming language itself. That language is built using very popular Pyrex specifications.
So, while Cython is a compiler in these terms, it has its own language
specifications as well that, of course, comply with the Python specifications.
works on the Just in Time compilation principle. Like interpreters, JIT compilers also pick up the raw code but turns the code into efficient machine code just before the execution.
There are a lot of optimization techniques involved in JIT compilers and
that makes JIT compilers work much faster than the raw interpreters. PyPy also consumes lesser memory at run time and hence has an advantage over raw Python interpreters.
You might want to understand the fact that while PyPy gives performance
gains and memory advantages, it is not always true. JIT compilers have
overheads as the compilers need to load at the run time, and for that reason, if your python execution processes are very small as compared to the JIT compiler overheads, the gains might not be evident.
PyPy is a . It will have its own space, improving over the
period of time, and for sure here to stay. You might want to do some
experiments with PyPy and see if it fits your use case.