Sorting numbers is ~1.4× slower than sorting strings
Numeric sort pays for comparator calls on every comparison, so it is slower than the default string sort. But default order puts '10' before '9', which is useless for numbers.
Result
| Run | 100k numbers (with comparator) | 100k strings (default order) | Ratio |
|---|---|---|---|
| Run 1 | 61.280 | 44.905 | 1.36× |
| Run 2 | 61.761 | 45.084 | 1.37× |
| Run 3 | 61.503 | 45.014 | 1.37× |
Conditions
Sorting a 100,000-element array five times (numbers with (a,b)=>a-b, strings with lexicographic default).
Where this number does not apply
If lexicographic order is acceptable (fixed-width codes), the default sort is faster. Correct numeric ordering requires the comparator, and this gap is what it costs.
Reproduce
cd bench
node --expose-gc micro-fixed.mjs --out ../data/run.json --samples 21 Run it three times on the same machine; if the spread of median stays under 10%, you should land on the same conclusion. If your numbers disagree, tell us and we will retract.