ES6 Map vs Object properties

JavaScript performance comparison

Revision 181 of this test case created by Antoine Theriault-Brunet

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() {
  const map = new Map();
  const obj = {};
  const keys = [];
  
  for (let i = 0; i < 10000; i++) {
    keys.push(randomString());
  }

};
</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
obj[key] = val;
for (let key of keys) {
  obj[key] = randomString();
}
pending…
map.get(key);
let val;
for (let key of keys) {
  val = map.get(key);
}
pending…
map.set(key, val)
for (let key of keys) {
  map.set(key, randomString());
}
pending…
obj[key]
let val;
for (let key of keys) {
  val = obj[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