ES6 Map vs Object properties

JavaScript performance comparison

Revision 18 of this test case created by Gabriel

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var map = new Map();
  var obj = {};
  
  var map2 = new Map();
  var obj2 = {};
  
  for (var i=0; i < 1000; i++) {
     var key = i.toString();
     var val = i;
     map2.set(key,val);
     obj2[key] = val;
  }
  
  map2.set('foo', 'bar');
  obj2['foo'] = 'bar';

};
</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
Set Map
for (var i=0; i < 1000; i++) {
   var key = i.toString();
   var val = i;
   map.set(key,val);
}
pending…
Set Object
for (var i=0; i < 1000; i++) {
   var key = i.toString();
   var val = i;
   obj[key] = val;
}
pending…
Iterate Map
for (var key of map2.keys()) {
  var val = map2.get(key);
}
pending…
Iterate Object
var keys = Object.keys(obj2);
for (var i = 0; i < keys.length; i++) {
    var val = obj2[keys[i]];
}
pending…
Get Map
var val = map2.get('foo');

for (var i=0; i < 1000; i++) {
   var key = i.toString();
   var val = map2.get(key);
}
pending…
Get Object
var val = obj2['foo'];

for (var i=0; i < 1000; i++) {
   var key = i.toString();
   var val = obj2[key];
}
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