ES6 Map vs Object Get

JavaScript performance comparison

Revision 235 of this test case created by Eric Anderson

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var smallMapStrings = new Map();
  var smallMapNumbers = new Map();
  var largeMapStrings = new Map();
  var largeMapNumbers = new Map();
  
  var smallObjStrings = {}
  var smallObjNumbers = {}
  var largeObjStrings = {};
  var largeObjNumbers = {};
  
  for (var i=0; i<10_000 ; i++) {
    if (i < 10) {
      smallMapStrings.set(`key${i}`, Math.random());
      smallMapNumbers.set(i, Math.random());
      smallObjStrings[`key${i}`] = Math.random();
      smallObjNumbers[i] = Math.random();
    }
    largeMapStrings.set(`key${i}`, Math.random());
    largeMapNumbers.set(i, Math.random());   
    largeObjStrings[`key${i}`] = Math.random();
    largeObjNumbers[i] = Math.random();
  }

};
</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
smallMapStrings.get(hit)
let temp = smallMapStrings.get("key0");
pending…
largeMapStrings.get(hit)
let temp = largeMapStrings.get("key0");
pending…
largeMapNumbers.get(hit)
let temp = largeMapNumbers.get(0);
pending…
smallObjNumbers[hit]
let temp = smallObjNumbers[0];
pending…
smallMapNumbers.get(hit)
let temp = smallMapNumbers.get(0);
pending…
largeObjNumbers[hit]
let temp = largeObjNumbers[0];
pending…
largeObjStrings[hit]
let temp = largeObjStrings["key0"];
pending…
smallObjStrings[hit]
let temp = smallObjStrings["key0"];
pending…

Revisions

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

0 Comments