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.

Two inputs changed

Control

Cache off

1,000 requests

Treatment

Cache on

500 requests

Elapsed time depends on the whole comparison.

An illustration of the invented design: cache condition and workload change together. The observed difference combines both changes; normalising a column does not automatically identify the cache effect.

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

Editor tools
About Python ↗

Ctrl+Enter or ⌘+Enter runs the code.

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?

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?

Choose an answer

Hints for this question
  1. List everything that changes with the treatment.
  2. Ask which alternative explanation fits the same difference.
Your notes