ES6 Map vs Object Get (v243)

Revision 243 of this benchmark created on


Setup

var mapStr = new Map();
  var objStr = {};
  var mapNum = new Map();
  var objNum = {};
  
  for (let i=0; i<10000 ; i++) {
     mapStr.set(`${i}`, Math.random());
     objStr[`${i}`] = Math.random();
     mapNum.set(i, Math.random());
     objNum[i] = Math.random();
  }

Test runner

Ready to run.

Testing in
TestOps/sec
[Number key] map.get
let temp;
let sum = 0;
for (let i=0; i < 10000; i++) {
   temp = mapNum.get(i);
   sum += temp;
}
console.log(`sum is ${sum}`);
ready
[String key] map.get
let temp;
let sum = 0;
for (let i=0; i < 10000; i++) {
   temp = mapStr.get(`${i}`);
   sum += temp;
}
console.log(`sum is ${sum}`);
ready
[Number key] obj[key]
let temp;
let sum = 0;
for (let i=0; i < 10000; i++) {
   temp = objNum[i];
   sum += temp;
}
console.log(`sum is ${sum}`);
ready
[String key] obj[key]
let temp;
let sum = 0;
for (let i=0; i < 10000; i++) {
   temp = objStr[`${i}`];
   sum += temp;
}
console.log(`sum is ${sum}`);
ready

Revisions

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