map vs array values

Benchmark created on


Setup

const array = new Array(98000).fill(crypto.randomUUID());

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

const arrayLength = array.length;
while (map.size < arrayLength) {
  map.set(crypto.randomUUID(), 1);
}

Test runner

Ready to run.

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

Revisions

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