Chapter 9. Speed Up Code with Cython

In this chapter, we will cover:

  • Installing Cython
  • Building a Hello World program
  • Using Cython with NumPy
  • Calling C functions
  • Profiling Cython code
  • Approximating factorials with Cython

Introduction

Cython is a relatively young programming language based on Python. The difference with Python is that we can optionally declare static types. Many programming languages, such as C, have static typing, which means that we have to tell C the type of variables, function parameters, and return types. Another difference is that C is a compiled language, while Python is an interpreted language. As a rule of thumb, we can say that C is faster but less flexible than Python. From Cython code, we can generate C or C++ code. After that, we can compile the generated code into Python extension modules.

In this chapter we will be learning about Cython. We will get some simple Cython programs running together with NumPy. Also we will profile Cython code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset