ES6 Map vs Object properties (v39)

Revision 39 of this benchmark created on


Description

Compare native Map implementation vs using an object as a hash map.

Preparation HTML

<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>

Setup

var map = new Map();
    var obj = Object.create(null);
    delete obj.x;
    
    var map2 = new Map();
    var obj2 = Object.create(null);
    delete obj2.x;
    
    for (var i = 0; i < 1000; i++) {
      var key = randomString();
      var val = randomString();
      map2.set(key, val);
      obj2[key] = val;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
map.set(key,val)
for (var i = 0; i < 1000; i++) {
  var key = randomString();
  var val = randomString();
  map.set(key, val);
}
ready
obj[key] = val;
for (var i = 0; i < 1000; i++) {
  var key = randomString();
  var val = randomString();
  obj[key] = val;
}
ready
Iterate Map
// async test
for (var [key, value] of map2.entries()) {
  var v = value,
    k = key;
}
ready
Iterate Object
// async test
for (var key in obj2) {
  var v = obj2[key],
    k = key;
}
ready
Iterate Map 2
// async test
map2.forEach(function(value, key) {
  var v = value,
    k = key;
});
ready

Revisions

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