Extend vs Prototype

Benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype
function MyObject(value1, value2, value3){
    this.value1 = value1;
    this.value2 = value2;
    this.value3 = value3;
    this.method1 =method1;
}

MyObject.prototype.update = function( args ) {
    for(var name in args) {
        this[ name ] = args[ name ];
    }
};

//using it
var instance1 = new MyObject( 1, 2, 3 );
instance1.update( {
    method2: method2,
    value4: 4
});
ready
jQuery extend
//generic object
function myObject(value1, value2, value3){
this.value1 = value1;
this.value2 = value2;
this.value3 = value3;
this.method1 =method1;
}

instance1 = new myObject(
1, //value1
2, //value2
3  //value3
)



jQuery.extend(instance1, {
    method2: method2
    value4: 4
})
ready

Revisions

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