Prototype vs Module pattern performance (v157)

Revision 157 of this benchmark created on


Preparation HTML

<script>
  function TraditionalPrototypeClass() {}
  TraditionalPrototypeClass.prototype.foo = function() {
    return 'foo';
  };
  TraditionalPrototypeClass.prototype.bar = function() {
    return 'bar';
  };

  function TraditionalClass() {

    this.foo = function() {
      return 'foo';
    };

    this.bar = function() {
      return 'bar';
    };

  }

  function ConstructOther() {
    //often seen in frameworks
    // constructor, but creates other object
    // this one is to be compared with traditional and literal versions
    return {
      foo: function() {
        return 'foo';
      },
      bar: function() {
        return 'bar';
      }
    };
  }

  
</script>

Setup

var o;

Test runner

Ready to run.

Testing in
TestOps/sec
Traditional Prototypal Class
o = new TraditionalPrototypeClass();
ready
Traditional Class
o = new TraditionalClass();
ready
Object Literal
o ={

  foo: function() {
    return 'a';
  },
  bar: function() {
    return 'b';
  }
}
ready
ConstructOther
o = new ConstructOther();
 
ready

Revisions

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