Constructor vs Object.create

Benchmark created by Lakshan on


Setup

var Person = function(first_name, last_name) {
        this.first_name = first_name;
        this.last_name = last_name;
    }
    
    Person.prototype = {
        say: function(msg) {
                return this.first_name + " says " + msg;
        }
    }
    
    var PersonMod = (function() {
        return {
                init: function(first_name, last_name) {
                        return Object.create(Person.prototype);
                }
        }
    
    })();

Test runner

Ready to run.

Testing in
TestOps/sec
Constructor
var ron1 = new Person("Ron", "Swanson");
ready
Object.create
var ron2 = PersonMod.init("Ron", "Swanson");
 
ready

Revisions

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

  • Revision 1: published by Lakshan on