ES6 Map vs Object properties

JavaScript performance comparison

Revision 218 of this test case created by Michael Hall

Preparation code


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();
}

      
<script>
Benchmark.prototype.setup = function() {
  
  var obj2 = {};
  for (var i=0; i < 10; i++) {
     obj2[preComputedRandomKeys[i]] = preComputedRandomVals[i];
  }
  

};
</script>

Preparation code output

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(); }

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

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(); }