ES6 Map vs Object properties

JavaScript performance comparison

Revision 278 of this test case created by Eser Ozvataf

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 arr = [];
  
  var map2 = new Map();
  var arr2 = [];
  
  for (var i=0; i < 1000; i++) {
     var key = i.toString();
     var val = randomString();
     map2.set(key,val);
     arr2.push({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
Access Array Item
var val = arr2.filter(x => x.key === '3');
pending…
Access Map Entry
var val = map2.get('3');
pending…

Revisions

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

0 Comments