Reading Performance of ES6 Map vs Object properties

JavaScript performance comparison

Revision 56 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var map = new Map();
  var obj = {};
  var hashSize = 10000;
  var testKeyNum = 20;
  var testkeys = [];
  
  for (var i = 0; i < hashSize; i++) {
      var key = randomString();
      var val = randomString();
      map.set(key, val);
      obj[key] = val;
  }
  
  var keys = Array.from(map.keys());
  for (var i = 0; i < testKeyNum; i++) {
      var testkey = keys[Math.random()*hashSize >>> 0];
      testkeys.push(testkey);
  }
  
  function randomString() {
      var text = "";
      var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  
      for( var i=0; i < 5; i++ )
          text += possible.charAt(Math.floor(Math.random() * possible.length));
  
      return text;
  }
  

};
</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
map.get(key)
for (var i = testkeys.length - 1; i >= 0; i--) {
  map.get(testkeys[i]);
}
pending…
obj[key]
for (var i = testkeys.length - 1; i >= 0; i--) {
  obj[testkeys[i]];
}
pending…

Compare results of other browsers

Revisions

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

0 Comments