O'Reilly logo

Python for Finance by Yves Hilpisch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 merging Python with C 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 compiling Python code for the CPU
  • NumbaPro, for dynamically compiling Python 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required