abstract-reference

JavaScript performance comparison

Revision 2 of this test case created by Andrea Giammarchi

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var result = [];
  
  // Multiple WeakMaps approach
  var PrivateCoordinatesMWM = (function () {
  
    var
      _x = new WeakMap,
      _y = new WeakMap
    ;
  
    function PrivateCoordinatesMWM(x, y) {
      _x.set(this, x);
      _y.set(this, y);
    }
  
    PrivateCoordinatesMWM.prototype.toString = function toString() {
      return ''.concat(
        '[', _x.get(this), 'x', _y.get(this), ']'
      );
    };
  
    return PrivateCoordinatesMWM;
  
  }());
  
  // Single WeakMap approach
  var PrivateCoordinatesSWM = (function () {
  
    var _wm = new WeakMap;
  
    function PrivateCoordinatesSWM(x, y) {
      _wm.set(this, {x: x, y: y});
    }
  
    PrivateCoordinatesSWM.prototype.toString = function toString() {
      var _pvt = _wm.get(this);
      return ''.concat(
        '[', _pvt.x, 'x', _pvt.y, ']'
      );
    };
  
    return PrivateCoordinatesSWM;
  
  }());

};
</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
Multiple WeakMaps
result.push(
  new PrivateCoordinatesMWM(
    Math.random(),
    Math.random()
  ).toString()
);
pending…
Single WeakMap
result.push(
  new PrivateCoordinatesSWM(
    Math.random(),
    Math.random()
  ).toString()
);
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