instance method vs prototype method (v2)

Revision 2 of this benchmark created by Aleksy V Zapparov on


Preparation HTML

<script>
  var counter = 10000,
      collection = {};
  
  var Wasabi = function() {};
  Wasabi.prototype.noodle = function() {
   return true;
  }
  
  var Mustard = function() {
   this.noodle = function() {
    return true;
   };
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
instance method
for (counter; counter >= 0; counter -= 1) {
 collection[counter] = new Mustard();
}
ready
prototype method
for (counter; counter >= 0; counter -= 1) {
 collection[counter] = new Wasabi();
}
ready
Calling instance method
var m = new Mustard();

for (counter; counter >= 0; counter -= 1) {
 collection[counter] = m.noodle();
}
ready
Calling prototype method
var w = new Wasabi();

for (counter; counter >= 0; counter -= 1) {
 collection[counter] = w.noodle();
}
ready

Revisions

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

  • Revision 1: published by Couto on
  • Revision 2: published by Aleksy V Zapparov on