ES6 Map vs Object Get

JavaScript performance comparison

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

Revisions

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

0 Comments