Object vs prototype

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Object
function cloneObject (obj) {
    var newObj = {};

    for (var key in obj) {
        newObj[key] = obj[key];
    }

    return newObj;
}

var button = {
    method1: function () {
        console.log('method1 called');
    },
    method2: function () {
    }
};

var newButton = cloneObject(button);

newButton.method1();

 
ready
Prototype
function Button () {
}

Button.prototype.method1 = function () {
    console.log('method1 called');
};

Button.prototype.method2 = function () {
};

var newButton = new Button();
newButton.method1();
ready

Revisions

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