Chapter 13. Optimization: Solutions

Optimizing a program is not a magical process. It is done by following a simple process, synthesized by Stefan Schwarzer at Europython 2006 in an original pseudo-code example:

def optimize():
    """Recommended optimization"""
    assert got_architecture_right(), "fix architecture"
    assert made_code_work(bugs=None), "fix bugs"
    while code_is_too_slow():
        wbn = find_worst_bottleneck(just_guess=False,
        is_faster = try_to_optimize(wbn,
        if not is_faster:

# By Stefan Schwartzer, Europython 2006 

This chapter presents some solutions to optimize your program through:

  • Reducing the complexity

  • Multithreading

  • Multiprocessing

  • Caching

Reducing the Complexity

There are ...

Get Expert Python Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.