Ask a better questionLesson 03 of 30 · 6 min
Change, measure, hold steady
Separate the treatment, response and possible confounders in an experiment.
The treatment is the condition you deliberately assign, such as cache off or on. The response is the quantity you measure, such as elapsed milliseconds. Other variables may also affect the response: request count, machine load or input size.
A factor can confuse a treatment comparison if it differs between treatment groups and also affects the outcome. If every cache-on run uses half the requests, a lower time could come from the smaller job.
Inspect the invented table. Time per request helps reveal the unequal workloads, but dividing by request count does not automatically repair the design. Setup costs, queueing and different request mixes can make time per request change with workload. A fair follow-up holds the job fixed.
Control
Cache off
1,000 requests
Treatment
Cache on
500 requests
Elapsed time depends on the whole comparison.
Will comparing total times be enough when request counts differ?
Write a prediction (optional)
Run the prepared example
This page puts the example in the Python editor. Select Run Python with the code unchanged.
Invented data
A saved draft is open. To run the published example, open Editor tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
What to compare
Compare the requests, elapsed_ms and ms_per_request columns for the rows where cache is off and on. Do the rows compare equal amounts of work?
Your result
Result tools
The on rows cover fewer requests. Dividing elapsed time by requests shows a per-request average. Setup costs or workload differences can still affect it.
Published example output
The site ran the original code to produce this reference. Build environment ↗
cache requests elapsed_ms ms_per_request off 1000 100 0.100 off 1000 104 0.104 on 500 52 0.104 on 500 50 0.100
The on rows cover fewer requests. Dividing elapsed time by requests shows a per-request average. Setup costs or workload differences can still affect it.
Change and run again
In the Python editor, replace the requests list [1000, 1000, 500, 500] with [1000, 1000, 1000, 1000]. Leave elapsed_ms unchanged and select Run Python again. Which of the two elapsed-time columns changes? Could the edited numbers count as new measurements? Return to the Python editor
What this example supports. The table is invented and deliberately confounded. Normalisation relies on assumptions about how cost scales with work.
Try a fresh case
All treatment runs use a new machine, while all control runs use an old machine. What can you estimate directly?
Hints for this question
- List everything that changes with the treatment.
- Ask which alternative explanation fits the same difference.