Prototype property optimization

Benchmark created by voloko on


Setup

function Person1(name, age) {
      this.name = name;
      this.age  = age;
    }
    
    Person1.prototype.name = '';
    Person1.prototype.age  = '';
    
    
    function Person2(name, age) {
      this.name = name;
      this.age  = age;
    }
    
    
    function Person3() {
    }
    
    Person3.prototype.name = '';
    Person3.prototype.age  = '';
    
    
    
    function Person4() {
    }

Test runner

Ready to run.

Testing in
TestOps/sec
With prototype
var p = new Person1('foo', '10');
p.name += ' bar';
ready
Without prototype
var p = new Person2('foo', '10');
p.name += ' bar';
ready
With prototype, set after
var p = new Person3();
p.name = 'foo';
p.age  = '10';
p.name += ' bar';
ready
Without prototype, set after
var p = new Person4();
p.name = 'foo';
p.age  = '10';
p.name += ' bar';
ready
Simple object
var p = {
  name: 'foo',
  age: '10'
};
p.name += ' bar';
ready

Revisions

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

  • Revision 1: published by voloko on