array vs map (v5)

Revision 5 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 (let i = 0; i < mapLength; i++) {
  n++;
}
ready
array
const arrayLength = array.length;
let n = 0;
for (let i = 0; i < arrayLength; i++) {
  n++;
}
ready
map-of
let n = 0;
for (const [k, v] of map) {
  n++;
}
ready
map-each
let n = 0;
map.forEach(() => {
  n++;
});
ready
map-of-entries
let n = 0;
const entries = map.entries();
for (const [k, v] of entries) {
  n++;
}
ready
array-of
let n = 0;
for (const value of array) {
  n++;
}
ready
array-each
let n = 0;
array.forEach(() => {
  n++;
});
ready

Revisions

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