Overview

Overview#

Python is a versitile and widely used computer programming language:

  • High−level (allowing you to focus on your problem and not the hardware)

  • General purpose (can do many things)

  • Easy (and fun) to learn

  • Functions can be passed as arguments and can be returned from other functions

  • Open source

  • Large ecosystem of useful libraries and tools

  • It has sophisticated, convenient and useful syntax

  • It is evolving

This course focuses on how to measure and improve the performance of Python programs. It focusses on processing time whilst also considering memory utilisation. There are 4 parts:- Profiling

  • Data Structures, Algorithms and Libraries

  • Vectorisation

  • Compilers

Short breaks are timetabled for every 30 minutes and we have an hour for lunch from 12:30 to 13:30.

Think strategically#

There are usually trade-offs in changing code to do the same thing faster or using less memory:

  • The code may become significantly more complicated and less readable

  • A program that runs faster may require more memory

  • A program that requires less memory may run slower

  • The optimisations may only work well on specific platforms or with particular inputs

Before optimising code, consider the following:

  • Is the code complete and working?

    • Have you tested it?

    • Is it well documented?

  • Is optimisation really needed?

    • Have you profiled the code?

    • Is there a better computer that you can use? If optimisation seems sensible, then test if simple things (e.g. using a different function or data structure) make sufficient improvement before trying something complicated (e.g. parallelisation - which can be a more major undertaking and involve rethinking and rewriting algorithms)

Follow along#

  • Click on the Colab button within each Jupyter notebook to run there.

This is a practical course with exercises to help you learn. Hints for problems and solutions can be found on the Solutions page, but try to have a go without first referring to these. If you have a question, want help, want us to go over something again, please ask - raise your hand or ask in the Teams chat. We plan to use emoji polls in the chat to check in with you throughout the course. After the course has ended the Teams chat will remain open for the rest of this week in case you want to ask anything. We will post a final message in the chat to refer you to a general Teams channel where you can ask further about the course.