array vs map (v4)

Revision 4 of this benchmark created on


Setup

const array = new Array(98000).fill(Math.random);

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

Test runner

Ready to run.

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

Revisions

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