Code

The measuring harness

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

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

dcbench.go adds two commands. algo dc runs all four algorithms on the same order and prints the numbers; algo stable is the eight-row demonstration you will see in the next step.

As in lesson 7, every measurement checks the result first — isSortedByTitle. The speed of an incorrect sort means nothing.

And main.go — two lines, as usual: the dc and stable commands in usage and in the switch.

There is no test in this step: dcsort_test.go already has everything it needs. Remind yourself of two of its tests, which were preparing for this measurement:

  • TestNaivePivotIsQuadraticOnSortedInput asserts the worst case — exactly n(n−1)/2. You will see that number in the measurement in step 8.
  • TestQuickSortIsNotStable asserts a defect. It appears in the next step as eight rows.

First run

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

A four-row table should appear: comparisons, moves, time. The same two columns you have been counting by hand until now.