Finding indexes of elements (v4)

Revision 4 of this benchmark created on


Setup

const size = 1000000000;

const updatedRows = Array.from(size, (_, i) => i + 1);
const rows = Array.from(size, (_, 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
Using loops
const result = new Array(updatedRows.length);

for (let i = 0; i < result.lenght; i++) {
	result[i] = rowsMap.get(row)
}

console.log(result);
ready
Using loops and indexOf
const result = new Array(updatedRows.length);

for (let i = 0; i < result.lenght; i++) {
	result[i] = rows.indexOf(updatedRows[i]);
}

console.log(result);
ready

Revisions

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