Course name: | Faster Python Programs through Optimization |
Course length: | 1 day |
Remote: | Yes |
Open course: | Yes |
In-house: | Yes |
Course ID: | OPE |
German course | here |
Company courses allow to assemble trainings combining topics from different courses.
You can download our flyer. It has an overview of all our course topics.
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.
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.
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.
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 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.
We use a computationally demanding example and implement it first in pure Python. We look at some algorithmic improvements to speed up the computation.
Measuring how fast a program really run is no simple task. We look at solutions to this problem in Python.
PyPy is a different implementation that has a Just-in-Time-Complier (JIT). It is full Python 2.7 compliant implementation that has several very innovative features. The course introduces to the work with PyPy.
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.
The module multiprocessing
of the standard library allows to
take advantage of multiprocessor CPUs.
We will have a short tour through the module and apply it to our example.
We combine several of the strategies to get the maximum speed up.
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
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.
Every participant receives comprehensive materials in PDF format that cover the whole course content as well as all source code.
The module Python-Extensions with Other Languages covers supplementary topics. The course Python for Scientists and Engineers might also be of interest.
The course may be combined with the course Python for Non-Programmers or Python for Programmers
Tel: | +49 341 260 3370 |
Fax: | +49 341 520 4495 |
mail: | info@python-academy.de |
Tel: | +49 341 260 3370 |
Fax: | +49 341 520 4495 |
mail: | info@python-academy.de |