Theory

Zero comparisons

$ algo count -in s100k.jsonl
n = 100000, key = Rating (0..100, so k = 101)

algorithm                       comparisons            moves         wall
counting                                  0           100000      3.017ms
sort.SliceStable                    1432948         (hidden)     93.609ms
insertion (lesson 7)             2503832821       2503732834   26.316217s

Compare that with your guess from step 1.

Zero. Not "fewer" — none. A hundred thousand items sorted without a single comparison between two items.

And exactly 100,000 moves — one per item. Every element is placed once and never touched again. Compare with lesson 7's 2,503,732,834.

Time: 3 ms against 93.6 ms for the standard library (31×) and 26.3 s for insertion sort (8,700×).

Where did the work go

Nowhere — it changed shape. Instead of asking "does A come before B?" n log n times, you pass over the data once and count. The key names the position itself.

That is only possible because the key is a small integer with known bounds. Which is exactly why Rating has had limits since lesson 1.

The cost the table does not show

The count array has k slots — 101 here.

That is memory a comparison sort never needs, and it depends not on how much data you have but on how large the value space is. A hundred items: 101 slots. A hundred million items: still 101.

In that direction the trade is excellent. In the other direction it collapses, and that is the next step.

Gotcha

In lesson 4 you learned that the counter cannot see memory. This table is a precise example: nothing in the counting row shows the 101-slot array. The numbers are correct and incomplete at the same time.