Faster Python Code
2h 5mAdvanced2018-03-20
Authors

Miki Tebeka
CEO at 353Solutions
Course details
By optimizing your Python code, you can ensure that your code uses fewer resources and runs faster than it did previously. In this advanced course, explore tips and techniques that can help you optimize your code to make it more efficient. Instructor Miki Tebeka covers general tools of the trade, including how to leverage the tools Python provides for measuring time, and how to use line_profiler to get line-by-line profiling information. Miki also shares how to pick the right data structures, how approximation algorithms can speed up your code, and how to use NumPy for fast numeric computation. He wraps up the course with a discussion of how to integrate performance in your process.
Learning objectives
Rules of optimization
Measuring time
Using line_profiler
Picking the right data structure
Using the bisect module
Memory allocation in Python
Caching, cheating, and parallel computing
NumPy, Numba, and Cython
Design and code reviews
Learning objectives
Rules of optimization
Measuring time
Using line_profiler
Picking the right data structure
Using the bisect module
Memory allocation in Python
Caching, cheating, and parallel computing
NumPy, Numba, and Cython
Design and code reviews
Skills covered
PythonProgramming LanguagesOpen SourceSoftware DevelopmentOne-Off
Concepts
Introduction
- Welcome
- What you should know
Tools of the Trade
- Always profile first
- General tips
- Measuring time
- CPU profiling
- line profiler
- Tracing memory allocations
- memory profiler
Picking the Right Data Structure
- Big-O notation
- bisect
- deque
- heapq
- Beyond the standard library
Tricks of the Trade
- Local caching of names
- Remove function calls
- Using slots
- Built-ins
- Allocate
Caching
- Overview
- Pre-calculating
- lru cache
- Joblib
Cheating
- When approximation is good enough
- Cheating example
Parallel Computing
- Amdahl's Law
- Threads
- Processes
- asyncio
Beyond Python
- NumPy
- Numba
- Cython
- PyPy
- C extensions
Adding Optimization to Your Process
- Why do we need a process
- Design and code reviews
- Benchmarks
- Monitoring and alerting
Conclusion
- Next steps