Lesson 22 of 23 · 2:39
When preparation pays: a fair comparison
Evaluate preparation tradeoffs with declared costs and matching output contracts.
Keyboard: focus the player, then Space or K to play/pause and arrow keys to seek. Tab moves through the controls. Selectable captions replace the video's caption strip with the same timed text below.
In this lesson
- 0:00 · When does preparation repay its cost?
- 0:25 · Declare the model before calculating
- 0:46 · Write the total-cost equations
- 1:02 · Solve the break-even point
- 1:20 · Check below and above the crossover
- 1:39 · Plan a real measurement boundary
- 1:57 · Your turn: the first strict improvement
- 2:21 · Answer: forty-nine queries
Complete transcript
This transcript includes the answers to prediction prompts.
Show transcript
When does preparation repay its cost? · 0:00
When does preparation repay its cost? A reusable representation can take time to build before it answers a query. We will compare total time for the same queries and the same output, using an explicitly hypothetical example. You will learn to include the build cost, locate equality, and distinguish it from the first strict improvement.
Declare the model before calculating · 0:25
Assume direct evaluation takes three milliseconds per query. The prepared method costs one hundred twenty milliseconds to build and half a millisecond per query. Both return the same single Boolean answer for each input. These numbers illustrate a method; they are not measurements of this repository.
Write the total-cost equations · 0:46
Let N be the number of queries. Direct evaluation costs three N milliseconds. The prepared path costs one hundred twenty plus half N. The build cost is paid once only if the prepared artifact can actually be reused across those queries.
Solve the break-even point · 1:02
Set the two costs equal. Subtract half N from both sides, giving two and a half N equals one hundred twenty. Divide to obtain forty-eight queries. At exactly forty-eight, both paths take one hundred forty-four milliseconds under our assumptions.
Check below and above the crossover · 1:20
At ten queries, direct evaluation takes thirty milliseconds, while preparation plus queries takes one hundred twenty-five. At one hundred queries, direct takes three hundred and prepared takes one hundred seventy. The preferable path changes with reuse, even though each prepared query is faster.
Plan a real measurement boundary · 1:39
A real experiment must say whether parsing, compilation, caches, conversion, and final output are included. Use the same inputs, verify results first, and report repeated measurements with host and software details. A warm cached run and a cold run answer different questions.
Your turn: the first strict improvement · 1:57
In our hypothetical model, equality occurs at forty-eight queries. What is the smallest whole number of queries for which the prepared method is strictly faster? Calculate both totals there rather than rounding the equality point into a claimed win.
Prediction pause: 10 seconds.
Answer: forty-nine queries · 2:21
At forty-nine queries, the direct total is one hundred forty-seven milliseconds. The prepared total is one hundred forty-four and a half. That is the first whole-query count with a strict improvement in this model. Different build or query costs would change the crossover.

