Obj vs Map

Edit on GitHub

Object lookup vs. map

Setup

const obj = {};
const map = new Map();
for (let i = 0; i < 10000; i++) {
  obj[i] = i;
  map.set(i, i);
}
function rand() {
  return Math.floor(Math.random() * 10000);
}

Tests

  • Obj

    for (let i = 0; i < 100000; i++) {
      const x = obj[rand()];
    }
  • Map

    for (let i = 0; i < 100000; i++) {
      const x = map.get(rand());
    }