Chapter 4. Profiling and Optimization

In this chapter, we will cover the following topics:

  • Evaluating the time taken by a command in IPython
  • Profiling your code easily with cProfile and IPython
  • Profiling your code line-by-line with line_profiler
  • Profiling the memory usage of your code with memory_profiler
  • Understanding the internals of NumPy to avoid unnecessary array copying
  • Using stride tricks with NumPy
  • Implementing an efficient rolling average algorithm with stride tricks
  • Processing large NumPy arrays with memory mapping
  • Manipulating large arrays with HDF5

Introduction

Although Python is not generally considered one of the fastest language (which is somewhat unfair), it is possible to achieve excellent performance with the appropriate methods. This is ...

Get IPython Interactive Computing and Visualization Cookbook - Second Edition 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.