ES6 Map vs Object properties

JavaScript performance comparison

Revision 220 of this test case created by Michael Hall

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  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;
  }
  
  var preComputedRandomKeys = [];
  var preComputedRandomVals = [];
  
  for (var i=0; i < 10; i++) {
     preComputedRandomKeys[i] = randomString();
     preComputedRandomVals[i] = randomString();
  }
  
  var item_activityProperties = {};
  for (var i=0; i < 10; i++) {
     item_activityProperties[preComputedRandomKeys[i]] = preComputedRandomVals[i];
  }
  
  console.log(item_activityProperties)

};
</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
declarativeModelFieldsObject
let declarativeModelFieldsObject = {};
for (const [key, field] of Object.entries(item_activityProperties)) {
	declarativeModelFieldsObject[key] = field.value;
}
pending…
declarativeModelFieldsObjectFromMap
let declarativeModelFieldsMap = new Map();
for (const [key, field] of Object.entries(item_activityProperties)) {
	declarativeModelFieldsMap.set(key, field.value);
}
let declarativeModelFieldsObjectFromMap = Object.fromEntries(declarativeModelFieldsMap.entries());
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