Experiment design lab

Plan a fair, repeatable experiment, then see measurement noise for yourself.

1 · Plan your experiment

Controlled variables: tick the ones you will keep constant

2 · See why repeats matter: a benchmark in your browser

Time real sorting code on this device. Run it twice with 1 repeat and compare, then with 20 repeats.

Things to notice
  • With 1 repeat, run it twice: the times change. That spread is noise, not the algorithm.
  • The first run is often slower (the browser compiles the code as it goes). That is why you do warm-up runs.
  • Comparisons don't change between runs of the same data: counting operations is hardware-independent. Use both counts and times.
  • Doubling n roughly quadruples insertion sort's time on random data (O(n²)), but try “Already sorted”.
  • Is the gap between two algorithms bigger than the error bars? If not, you can't claim one is faster.