Locale compare vs collator compare

Benchmark created on


Setup

const unordered_array = ['1b', '1a', 'b', 'a'];
const unordered_array2 = ['1b', '1a', 'b', 'a'];
const collator = new Intl.Collator(undefined, { numeric: true });

Test runner

Ready to run.

Testing in
TestOps/sec
Collator
unordered_array.sort(collator.compare);
ready
Locale compare
unordered_array2.sort((a, b) => a.localeCompare(b, { numeric: true }));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.