Exercise 1: Extending the Insert-Timing Measurement to 3,000 Rows — Possible Solution ==================================================================== THE TEST ------------------------------ t500 = measure_full_rewrite_inserts(500) t3000 = measure_full_rewrite_inserts(3000) ratio = t3000 / t500 RESULT ------------------------------ 500 inserts: 0.165s 3000 inserts: 1.877s ratio: 11.37x 3,000 inserts is 6x the data of 500 inserts. A linear relationship would predict the time also grows by exactly 6x. The real, measured ratio is 11.37x -- nearly double what linear scaling would predict. WHY THE RATIO IS WORSE THAN 6x, NOT JUST DIFFERENT ------------------------------ naive_insert_full_rewrite's own per-insert cost isn't constant -- it grows with however many rows are ALREADY stored, since every insert re-serializes the entire accumulated list. Insert number k has to write out k rows, not 1. Summing that cost across N total inserts (1 + 2 + 3 + ... + N) gives a total proportional to N(N+1)/2 -- a quadratic function of N, not a linear one. For N=500, that sum is about 125,250; for N=3000, it's about 4,501,500 -- a ratio of almost exactly 36x (6 squared), not 6x. The measured 11.37x is smaller than that theoretical 36x (real-world I/O has fixed per-write overhead that doesn't grow with data size, plus OS/filesystem caching effects that blunt the pure math), but it's still dramatically closer to "6 squared" territory than to a clean 6x -- confirming the same non-linear trend identified at the smaller 500-vs-2000 scale continues, and if anything intensifies, at a genuinely larger scale. WHY THIS WORKS AS AN ANSWER ------------------------------ Testing at a larger N than the chapter's own examples (500/1000/2000) rules out the possibility that the non-linear behavior was some kind of small-scale measurement artifact or a one-off anomaly -- the same underlying mechanism (re-serializing the whole accumulated dataset on every single write) keeps producing the same kind of disproportionate slowdown as N grows further, exactly as the O(N^2) analysis predicts.