ES6 Map vs Object Get

JavaScript performance comparison

Revision 243 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  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();
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/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}`);
pending…
[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}`);
pending…
[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}`);
pending…
[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}`);
pending…

Revisions

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

0 Comments