ES6 Map vs Object Get

JavaScript performance comparison

Revision 240 of this test case created by An Tran

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var map = new Map();
  var obj = {};
  
  for (var i=0; i<100_000 ; i++) {
     map.set(`${i}`, Math.random());
     obj[`${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;
for (let i=0; i < 10000; i++) {
   temp = map.get(i);
}
pending…
[String key] map.get
let temp;
for (let i=0; i < 10000; i++) {
   temp = map.get(`${i}`);
}
pending…
[String key] obj[key]
let temp;
for (let i=0; i < 10000; i++) {
   temp = obj[`${i}`];
}
pending…
[Number key] obj[key]
let temp;
for (let i=0; i < 10000; i++) {
   temp = obj[i];
}
pending…

Revisions

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

0 Comments