On Cython and speeding up Python code
I gave a brief talk on Cython during the February meet of the PythonPune meetup group.
The talk I had in mind when I had proposed the session and the one I ended up delivering at the meet were very different, mainly because I wanted to limit the scope of the talk. Initially, I wanted to dive into Cython and give numerous code examples. However, when I finally sat down the make the presentation, I chose to lay back and give an overview of why Cython is needed in the first place and other ways to speed up Python code.
I talked about how Cython can be used to speedup Python routines and work with existing C/C++ code bases. I took a detour and asked the audience why Python was slow in the first place, in comparison to C/C++/Java/JavaScript. After driving the difference between interpreted, compiled and JIT-compiled languages, I introduced JIT compilers available in Python land e.g. Psyco, PyPy and Pyjion. PyPy is the most popular alternative compiler to the Python language but isn't as widely used as the standard CPython compiler. I also mentioned the numba library and how it allows specific functions to be JIT-compiled instead of having to compile Cython code or use a JIT-compiler.
Moving on, after establishing Cython as a way to speedup Python code, I introduced the Cython language, which is a superset of the Python language. Using the example of a small function, I introduced the syntax of the Cython language. Finally, I introduced the Cython library and how it can be used to compile the Cython code.
The talk was well received in my opinion. We had a lively discussion during and after the talk on speeding up Python code and I tried answering a few question on Cython.
The slides for the talk are available online. Comments, suggestions and feedback are welcome and highly appreciated. You can directly comment on the Google Slides if you wish to provide feedback. Or comment on this blogpost.
The talk I had in mind when I had proposed the session and the one I ended up delivering at the meet were very different, mainly because I wanted to limit the scope of the talk. Initially, I wanted to dive into Cython and give numerous code examples. However, when I finally sat down the make the presentation, I chose to lay back and give an overview of why Cython is needed in the first place and other ways to speed up Python code.
I talked about how Cython can be used to speedup Python routines and work with existing C/C++ code bases. I took a detour and asked the audience why Python was slow in the first place, in comparison to C/C++/Java/JavaScript. After driving the difference between interpreted, compiled and JIT-compiled languages, I introduced JIT compilers available in Python land e.g. Psyco, PyPy and Pyjion. PyPy is the most popular alternative compiler to the Python language but isn't as widely used as the standard CPython compiler. I also mentioned the numba library and how it allows specific functions to be JIT-compiled instead of having to compile Cython code or use a JIT-compiler.
Moving on, after establishing Cython as a way to speedup Python code, I introduced the Cython language, which is a superset of the Python language. Using the example of a small function, I introduced the syntax of the Cython language. Finally, I introduced the Cython library and how it can be used to compile the Cython code.
The talk was well received in my opinion. We had a lively discussion during and after the talk on speeding up Python code and I tried answering a few question on Cython.
The slides for the talk are available online. Comments, suggestions and feedback are welcome and highly appreciated. You can directly comment on the Google Slides if you wish to provide feedback. Or comment on this blogpost.