array vs map

Benchmark created on


Setup

const array = new Array(100000).fill(Math.random * 93452);

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

Revisions

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