Sort bench

Benchmark created on


Setup

const arr = [];
for (let i = 0; i < 2000; i++) {
  arr.push(`test-${Math.random()}`);
}
const arr1 = arr.slice();
const arr2 = arr.slice();
const arr3 = arr.slice();

Test runner

Ready to run.

Testing in
TestOps/sec
sort localeCompare
arr1.sort((a, b) => a.localeCompare(
  b,
  undefined, {
    numeric: true,
    sensitivity: 'base'
  }
));
ready
sort Intl collator
const collator = new Intl.Collator('en', {
  numeric: true,
  sensitivity: 'base'
});
arr2.sort((a, b) => collator.compare(a, b));
ready
sort a<b
arr3.sort((a, b) => (a < b ? -1 : (a > b ? 1 : 0)));
ready

Revisions

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