prototype vs closures

JavaScript performance comparison

Revision 75 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function Person(name, getter, setter) {
  	  this.name = name;
      if (getter) this.getName = getter.bind(this);
      if (setter) this.setName = setter.bind(this);
  }
  Person.prototype.getName = function(){ return this.name; };
  Person.prototype.setName = function(name){ this.name = name; };
  
  
  var proto = {getName: function(){ return this.name; },
               setName: function(name){ this.name = name; }
  };
  
  var _p = new Person('John');
  var _c = new Person('John', proto.getName, proto.setName);

};
</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
Prototype init
var p = new Person('John', proto.getName, proto.setName);
pending…
Closure init
var c = Person('John');
pending…
Prototype read
_p.getName();
pending…
Closure read
_c.getName();
pending…
Prototype write
_p.setName('Jane');
pending…
Closure write
_c.setName('Jane');
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