Finding indexes of elements (v3)

Revision 3 of this benchmark created on


Setup

const updatedRows = Array.from(1000000, (_, i) => i + 1);
const rows = Array.from(1000000, (_, i) => i + 1);

const rowsMap = new Map(rows.map((row, index) => [row, index]));

Test runner

Ready to run.

Testing in
TestOps/sec
Using indexOf
const result = updatedRows.map(
  (row) => rows.indexOf(row)
).filter((i) => i !== -1);

console.log(result);
ready
Using Map

const result = updatedRows
      .map(row => rowsMap.get(row))
      .filter((index) => index !== undefined);

console.log(result);
ready

Revisions

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