Module vs prototype

Benchmark created on


Description

Compares speed of module patter (e.g., return {// ...};) vs prototype based objects

Preparation HTML

<script>
  var ProtoObj = function(_a, _b, _c) {
      this.a = _a;
      this.b = _b;
      this.c = _c;
      }
      
  ProtoObj.prototype.func1 = function() {
    return this.a;
  }
  ProtoObj.prototype.func2 = function() {
    return this.b;
  }
  ProtoObj.prototype.func3 = function() {
    return this.c;
  }
  
  var ModuleObj = function(_a, _b, _c) {
      return {
        a: _a,
        b: _b,
        c: _c,
  
        func1: function() {
          return this.a;
        },
        func2: function() {
          return this.b;
        },
        func3: function() {
          return this.c;
        }
  
      };
      }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Module Object Creation
var test = new ModuleObj();
ready
Prototype Object Creation
var test = new ProtoObj();
ready

Revisions

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