Knockout Prototype vs Instance

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var A = function() {
      var self = this;
      self.name = ko.observable(1);
      self.addToList = function() {
        self.name(self.name() + 1)
      };
    };
   
    var B = function() {
      var self = this;
      self.name = ko.observable();
   
      self.addToList = self.addToList.bind(self.name);
    };
   
    B.prototype.addToList = function() {
      var name = this;
      name(name() + 1);
    };
   
    var C = {
       init:function(){ this.name = ko.observable(); },
       addToList: function(){ this.name(this.name() +1);}
    };
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Instance
var aIns = new A();
aIns.addToList()
pending…
Prototype
var bIns = new B();
bIns.addToList()
pending…
Object.create
var cIns = Object.create(C);
cIns.init();
cIns.addToList();
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. Here’s a list of current revisions for this page:

0 comments

Add a comment