Prototype vs Module pattern performance (v77)

Revision 77 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 = {
       prop1: 'asdasd',
       prop2:  'asdsad',
       prop3:  'asdasd',
       prop4:  'asdasd',
       prop5: 'sdasd',
       testMethod: function() {
           return ins.prop1;
        }
       };
       return ins;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Prototypal
var a = context();
a.testMethod();
ready
Module pattern
var b = new Context();
b.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.