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 mergingPython
withC
paradigms 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 compilingPython
code for the CPU -
NumbaPro
, for dynamically compilingPython
code 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
]:
def
perf_comp_data
(
func_list
,
data_list
,
rep
=
3
,
number
=
1
):
''' Function to compare the performance of different functions.
Parameters
==========
func_list : list
list with function names as strings
data_list : list ...
Get Python for Finance now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.