Prototype vs Module pattern performance (v73)

Revision 73 of this benchmark created on


Setup

function context() {
       var ins = {};
       ins.prop1 = 'asdasd';
       ins.prop2 = 'asdsad';
       ins.prop3 = 'asdasd';
       ins.prop4 = 'asdasd';
       ins.prop5 = 'sdasd';
       ins.testMethod = function() {
          return ins.prop1;
       }
       return ins;
    }
    
    function Context() {
       var ins = this;
       ins.prop1 = 'asdasd';
       ins.prop2 = 'asdsad';
       ins.prop3 = 'asdasd';
       ins.prop4 = 'asdasd';
       ins.prop5 = 'sdasd';
       ins.testMethod = function() {
          return ins.prop1;
       }
    }
    
    function context2() {
       var ins = {
       ins.prop1: 'asdasd',
       ins.prop2:  'asdsad',
       ins.prop3:  'asdasd',
       ins.prop4:  'asdasd',
       ins.prop5: 'sdasd',
       ins.testMethod: function() {
          return ins.prop1;
       }
       };
       return ins;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Prototypal
var c = context();
c.testMethod();
ready
Module pattern
var c = new Context();
c.testMethod();
ready
asdsadasd
var c = context2();
c.testMethod();
ready

Revisions

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