array vs map (v7)

Revision 7 of this benchmark created on


Setup

const arrayLength = 98000;
const array = [];
for (let i = 0; i < arrayLength; i++) {
  array[i] = {d: i};
}

const map = new Map();
array.forEach((n, i) => {
  map.set(i, n);
});

Teardown

console.log(array)

Test runner

Ready to run.

Testing in
TestOps/sec
map
let n = 0;
for (const [k, v] of map) {
  n += v;
}
ready
array
const arrayLength = array.length;
let n = 0;
for (let i = 0; i < arrayLength; i++) {
  n += array[i];
}
ready

Revisions

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