Constructor vs augmentor

JavaScript performance comparison

Test case created by Athan Clark

Info

This test is a comparison of two object-changing-and-inspection methodologies - add a new property via a constructor with the object as it's parameter, or pass the object as a parameter to the augmentor, where the augmentor does the dual-linking etc.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Construct(param) {
      this.par = param;
    }
   
    function augmentor(param) {
      param.child = { par: param };
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Constructor
var obj = {};

obj.child = new Construct(obj);
pending…
Augmentor
var obj = {};

augmentor(obj);
pending…

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

Compare results of other browsers

0 comments

Add a comment