P11: Make it 10x faster, with proof

The board shows a database taking in rows and reading them back. The program in this lesson reads a file of rows too, and the work is to find which part of that reading is slow.
Asha has a Python script that reads her company’s web server log and prints a daily report. Last month it took a few seconds. This month the log is bigger and the script takes much longer, so the report is late every morning. She has a free afternoon. She has one wrong idea about what to do with it: open the file and start rewriting the parts that look slow.
This lesson uses a made-up log of 300,000 lines and a script I wrote for it. Asha and the log are teaching values. Every time in this lesson is measured on one machine, a 16-core Linux computer running Python 3.12.3, on 28 November 2026. Your times will differ. The ratios between them will be close.
By the end of this lesson you will be able to take a slow program, find its slowest part by measuring, fix that one part, measure again, and show a before-and-after table that proves how much faster it got.
The history (optional)
Donald Knuth wrote in “Structured Programming with go to Statements” (Computing Surveys, December 1974) that programmers should forget small efficiencies “about 97% of the time”, and that “premature optimization is the root of all evil”. The next sentence says not to pass up the critical 3%. Finding the 3% needs measurement, which is this lesson.
Before you start. You need Watching a live machine: perf, strace and flame graphs, which showed a sampling profile: a program is stopped many times a second and the chain of function calls is written down each time. You need P6: A model you can defend, where a baseline is the first score you put next to every later score. You need A repo a stranger can judge in two minutes, which says a project page should show measured results. This lesson gives you the measured result for speed.