array vs map (v8)

Revision 8 of this benchmark created on


Setup

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

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

Test runner

Ready to run.

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

Revisions

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