Chapter 8. Performance Python
Don’t lower your expectations to meet your performance. Raise your level of performance to meet your expectations.
— Ralph Marston
When it comes to performance-critical applications two things should always be checked: are we using the right implementation paradigm and are we using the right performance libraries? A number of performance libraries can be used to speed up the execution of Python code. Among others, you will find the following libraries useful, all of which are presented in this chapter (although in a different order):
-
Cython, for mergingPythonwithCparadigms for static compilation -
IPython.parallel, for the parallel execution of code/functions locally or over a cluster -
numexpr, for fast numerical operations -
multiprocessing,Python’s built-in module for (local) parallel processing -
Numba, for dynamically compilingPythoncode for the CPU -
NumbaPro, for dynamically compilingPythoncode for multicore CPUs and GPUs
Throughout this chapter, we compare the performance of different implementations of the same algorithms. To make the comparison a bit easier, we define a convenience function that allows us to systematically compare the performance of different functions executed on the same or different data sets:
In[1]:defperf_comp_data(func_list,data_list,rep=3,number=1):''' Function to compare the performance of different functions.Parameters==========func_list : listlist with function names as stringsdata_list : list ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access