Code

The measuring harness

The test passes — all your functions are correct. Now we measure them.

Two files in this step, both complete. They are not your exercise.

ncbench.go adds algo count and algo radix. The first compares counting sort with comparison sorts on the same key; the second runs radix sort with both inner passes and shows the difference.

Note the output of algo radix: it prints not only sorted? but also the first place where the unstable variant breaks. Showing where it went wrong is more useful than reporting that it did.

main.go — two lines: the count and radix commands in usage and in the switch.

There is no test in this step: ncsort_test.go already has everything it needs. You met its three assertions that had no precedent in the last step — zero comparisons, exactly n moves, and that the unstable variant fails to sort. In this step they become numbers on the screen.

Why we compare on the same key

algo count sorts by Rating with both counting sort and sort.SliceStable. The same key, the same data — otherwise the comparison would mean nothing.

The insertion sort row in the table sorts by Title, and is marked as such. It is there for scale, not as a direct comparison.

First run

$ algo gen -n 1000 -seed 42 -o s1k.jsonl
$ algo count -in s1k.jsonl

A three-row table should appear. A thousand items cost nothing yet — you will see the real curve in the next step.