ES6 Map vs Object properties

JavaScript performance comparison

Revision 70 of this test case created by Joel Brage

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 = Object.create(null);
  
  var map2 = new Map();
  var obj2 = Object.create(null);
  var val = randomString();
  
  for (var i = 0; i < 10000; i++) {
    var key = i.toString();
    map2.set(key, val);
    obj2[key] = 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
For Object
var key = "";
var keys = Object.keys(obj2);
for (var i = 0; i < keys.length; i++) {
  var val = obj2[keys[i]];
}
pending…
Iterate Object
var key;
for (key in obj2) {
  var val = obj2[key];
}
pending…
Iterate Map
for (var key of map2.keys()) {
  var val = map2.get(key);
}
pending…
obj[key] = val;
var val = randomString();
for (var i = 0; i < 10000; i++) {
  var key = i.toString();
  obj[key] = val;
}
pending…
map.set(key,val)
var val = randomString();
for (var i = 0; i < 10000; i++) {
  var key = i.toString();
  map.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