ES6 Map vs Object properties

JavaScript performance comparison

Revision 43 of this test case created by

Preparation code

<script>
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>
      
<script>
Benchmark.prototype.setup = function() {
  var map = new Map();
  var obj = {};
  var keycache = [];
  var valcache = [];
  
  var map2 = new Map();
  var map3 = new Map();
  var map4 = new Map();
  var map5 = new Map();
  var obj2 = {};
  
  for (var i=0; i < 1000; i++) {
     var key = randomString();
     var val = randomString();
     map2.set(key,val);
     map3.set(key,val);
     map4.set(key,val);
     map5.set(key,val);
     obj2[key] = val;
     keycache[i] = key;
     valcache[i] = val;
  }

};
</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.set(key,val)
for (var i=0; i < 1000; i++) {
   var key = keycache[i];
   var val = valcache[i];
   map.set(key,val);
}
pending…
obj[key] = val;
for (var i=0; i < 1000; i++) {
   var key = keycache[i];
   var val = valcache[i];
   obj[key] = val;
}
pending…
Many Obj Creation
var objs = [],
    obj;
for (var i=0; i < 1000; i++) {
   obj = {};
   var key = keycache[i];
   var val = valcache[i];
   for (var j=0; j < 5; j++) {
      obj[key] = val;
   }
}
pending…
Many Map Creation
var objs = [],
    obj;
for (var i=0; i < 1000; i++) {
   obj = new Map();
   var key = keycache[i];
   var val = valcache[i];
   for (var j=0; j < 5; j++) {
      obj.set(key,val);
   }
}
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