prototype operator performance, saves memory, but is it faster (v2)

Revision 2 of this benchmark created by EWGL on


Preparation HTML

<script>
  var Y = function() {
   this.message = function(text) {};
   this.addition = function(a, b) {
    return a + b;
   };
   return this;
  }
  
  var X = function() {};
  X.prototype.message = function(text) {};
  X.prototype.addition = function(a, b) {
   return a + b;
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Y method is declared into the Javscript object class
for (i = 0; i < 1000; i++) {
 y = new Y();
 y.message('hi');
 y.addition(i, 2);
}
ready
X method is declared outside class by using protoype keyword
for (i = 0; i < 1000; i++) {
 x = new X();
 x.message('hi');
 x.addition(i, 2);
}
ready

Revisions

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

  • Revision 1: published by Marco Demaio on
  • Revision 2: published by EWGL on