Javascript Objects vs Map performance (v4)

Revision 4 of this benchmark created on


Setup

var mapKeyValue = new Map();
  var mapStringKeyValue = new Map();
  var objectKeyValue = {};
  var n = 100000;
  
  function makeid()
  {
      var text = "";
      var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  
      for( var i=0; i < 20; i++ )
          text += possible.charAt(Math.floor(Math.random() * possible.length));
  
      return text;
  }
  
  for(var i=0;i<n;i++) {
  	var value = makeid();
  	mapKeyValue.set(i, value);
    mapStringKeyValue.set(i+"",value);
  	objectKeyValue[i+""] = value;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
First Object from Map by Integer Key
mapKeyValue.get(0);
ready
First Object from Map by String key
mapStringKeyValue.get("0");
ready
First Object from Object by String Key
objectKeyValue["0"];
ready
Middle Object from Map by String Key
mapStringKeyValue.get("50000");
ready
Middle Object from Object by String Key
objectKeyValue["50000"];
ready
Last Object from Map by String Key
mapStringKeyValue.get("99999");
ready
Last Object from Object by String Key
objectKeyValue["99999"];
ready
Non-existent Object from Map by String
mapStringKeyValue.get("1231231");
ready
Non-existent Object from Object by String Key
objectKeyValue["1231231"];
ready

Revisions

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