Sort item to item selected list

Benchmark created on


Setup

const items = [];
for (let i = 0; i < 19_000; i++) {
  items.push({
    code: i.toString(),
  });
}

const selected = [];
for (let i = 0; i < 20_000; i++) {
  selected.push(i.toString());
}

Test runner

Ready to run.

Testing in
TestOps/sec
Sort Items
items.sort((a, b) => selected.indexOf(a.code) - selected.indexOf(b.code));
ready
Map Selected
const map = new Map(items.map(i => [i.code, i]));

const items2 = selected.map((sl) => map.get(sl)).filter(Boolean);
ready

Revisions

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