4 Designing for high performance
This chapter covers:
- Understanding time and space complexity
- Measuring the complexity of your code
- Choosing data types for different activities in Python
Once you’ve written working code, there’s usually additional work to do. Not only do you need it to accomplish its task, but also to accomplish it quickly. The performance of your code is how well it utilizes resources like memory and time. Software that performs at an acceptable level, meaning that it utilizes resources efficiently and responds to tasks within a desirable time frame, is said to be performant.
Software performance affects real-world people every day, whether they’re trying to upload their latest selfies to Instagram or doing real-time market analysis to pick stocks. How performant software should be often comes down to user perception. If something feels instantaneous, it might be fast enough.
Humans generally perceive changes faster than 100ms as instantaneous. If they click a button and the screen responds in 50ms, they’re happy. As responsiveness grows beyond 100ms, people begin to notice the lag. For long-running activities like downloading large files, lag can’t always be helped. In these cases, accurate progress updates are important because they change the perception of progress to feel faster.