factory vs constructor (v4)

Revision 4 of this benchmark created on


Description

When instantiating objects of the same class, is it faster to use the new keyword or just object literals?

Setup

function TestConstructor() {
      this.test = true;
      this.person = 'Matt';
      this.number = 9000;
    }
    
    var testFactory {
      test: true,
      animal: 'monkey',
      number: 8000
    };

Test runner

Ready to run.

Testing in
TestOps/sec
new
new TestConstructor();
ready
object create
Object.create(testFactory);
ready

Revisions

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