Home >>> Courses >>> Special Topics >>> Optimizing

What customers say ...

Mike is an outstanding teacher ... I will look for his classes in the future.

Jennifer Trasti, Software/Systems Engineer, Sandia National Laboratories, Albuquerque, NM, USA more...

I enjoyed the course very much and learned a lot. My interest for quite few of topics was ignited during the course and I will into more details. I understood many principles. All in all: Very good training! Thank you very much all the best.

Dominik Schwinn, German Aerospace Stuttgart about the course "Python für Programmierer und Python für Wissenschaftler und Ingenieure" more...

Good course. Very competent trainer for this introduction. The course offers wide spectrum of topics and goes into depth were participants need it most.

Helmut Dittrich, CEO DiFis-Engineering UG, arrow-fix.com, about the German introduction to Django "Einstieg in Django" more...

Course curriculum and delivery absolutely goal-oriented very understandable. Highly recommended!!!

Ralf Dörksen, Sangross about the course "Introduction to Django" more...

Very good introduction to the programming language.

Matthias Enderle, freelancer programmer about the German version of the course "Python for Programmers" more...

Module - Optimizing Python Programs

Dates for Open Courses

Course available as open and in-house training. Currently no dates for open courses. Please ask us at info@python-academy.de


Python is an interpreted language; Python source code is translate into portable byte code. This concept in combination with other design principles of Python makes many of advantages as compared to other languages possible. As a drawback the execution speed my be considerably slower for certain kinds of applications than with compiled languages. Optimization can often increase performance of Python programs substantially.

Course Content

Guidelines for Optimization

Python programs are not principally slow. On the contrary: the execution speed is sufficient for many application. The basic question is if the program serves its intended purpose. Furthermore, other factors such as database access or network connections may determine the speed of the application.

The course provides important guidelines for optimization.

Optimization Strategies

The concept of benchmarking with pystone is introduced with examples for different Python implementations. Profiling of CPU usage can be used to find the spots of a program that use up most of the program run time. The built-in module cProfile is used in the course. Examples of common cases will help to understand how to use them. Memory usage will be measured with the heapy module from the Guppy_PE framework. Different possibilities of its usage are explored with examples.

Participants are encouraged to bring their own programs for profiling to the course.

Algorithms and Anti-Patterns

Typically the larges gains of performance can be achieved through algorithmic changes.

Algorithms that are especially slow or fast in Python are shown. We look at string concatenation and we use generators to minimize memory usage.

The Right Data Structure

The data structure can have significant impact on execution speed. We look at the built-in data structures compare lists, sets, deque and defaultdict. The big-O notation will be exemplified.


Caching can be a useful strategy to reduce run times. We look at deterministic and non-deterministic caching and develop decorates for these purposes.

The Example

We use a computationally demanding example and implement it first in pure Python. We look at some algorithmic improvements to speed up the computation.

Testing Speed

Measuring how fast a program really run is no simple task. We look at solutions to this problem in Python.


Psyco is a so called "just-in-time-complier" (JIT), which allows to translate parts of the byte code to machine code. This may yield considerable speed improvements.

Examples are used to show the different possibilities of using Psyco. Participants are encouraged to bring their own programs to the course to optimize them.

Numerical Calculations with NumPy

Numerical calculations using large list are rather slow in Python. The dynamical typing can use up lots of performance. The library NumPy offers efficient processing of numerical arrays. Functionality and usage are inspired by MATLAB.

The basic possibilities of NumPy are covered in the course.

Using Multiple CPUs with pyprocessing/multiprocessing

The module pyprocessing is, renamed as multiprocessing part of the standard library of Python 2.6. It allows to take advantage of multiprocessor CPUs. We will have a short tour through the module and apply it to our example.

Combination of Optimization Strategies

We combine several of the strategies to get the maximum speed up.

Overview of Extensions to Python with Other Languages

The speed of Python programs can be increased through extensions written in other languages. An overview of possibilities to extend Python are given if this module is not combined with the module Python-Extensions with Other Languages.

Module Duration

1 day


The participants can follow all steps directly on their computers. There are exercises at the end of each unit providing ample opportunity to apply the freshly learned knowledge.

Course Material

Every participant receives comprehensive printed materials that cover the whole course content as wells as a CD with all source codes and used software.

The Python Academy is sponsor of PyCon Montréal 2015.

[PyCon Montréal 2015]

The Python Academy is sponsor of Python BarCamp Köln 2015.

[Python BarCamp 2015]“ border=

The Python Academy is sponsor of Chemnitzer Linux-Tage 2015.

Chemnitzer Linux-Tage 2015 - 21. und 22. März 2015

The Python Academy is sponsor of Django Girls Wroclaw 2015.

[Django Girls Wroclaw 2015]

The Python Academy is sponsor of PyCon Ireland 2014.

[PyCon Ireland 2014]

The Python Academy is sponsor of EuroSciPy 2014.

[EuroSciPy 2014]

The Python Academy is sponsor of PyData London 2014.

[PyData London 2014]

The Python Academy is sponsor of EuroPython 2014.

[EuroPython 2014]

The Python Academy is sponsor of PyCon 2014 Montréal.

[PyCon 2014 Montréal]

The Python Academy is sponsor of Python BarCamp Köln 2014.

[Python BarCamp 2014]

The Python Academy is sponsor of PyConDE 2013.

[PyCon DE 2013]

The Python Academy is sponsor of EuroPython 2013.

[EuroPython 2013]

The Python Academy is sponsor of PyCon US 2013.

[PyCon US 2013]

The Python Academy is sponsor of EuroSciPy 2013.

[EuroSciPy 2013]

The Python Academy is sponsor of PyConPL 2012.

[PyCon PL 2012]


The next open cousers
details ...

Python Academy sponsors EuroPython conference 2013
details ...

Python Academy sponsors EuroSciPy conference 2013
details ...

Python Academy sponsors Python BarCamp in Cologne
details ...

Next Meeting of Leipzig Python User Group, November 12, 2013
details ...

Introduction to Django, November 11 - 13, 2013
details ...

Professional Testing with Python, November 25 - 27, 2013
details ...

Advanced Django, January 13 - 15, 2014
details ...

Python Academy sponsors PyCon US conference 2013
details ...

Python Academy founder receives PSF Community Service Award
details ...