Dynamic arguments to the constructor (v3)

Revision 3 of this benchmark created by rock on


Description

Test which way of creation object by given constructor and ARRAY of arguments are faster: + Fake constructor creation; + Function.prototype.bind method

Setup

function MyClass(a,b,c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }
    
    function construct(ctor, args) {
        var i = Object.create(ctor.prototype)
          , r = ctor.apply(i, args);
        return r != null && (typeof r == 'object' || typeof r == 'function') ? r : i;
    }
    var result;

Test runner

Ready to run.

Testing in
TestOps/sec
Function.prototype.bind
result = new (Function.prototype.bind.apply(MyClass, [null].concat([1, 2, 3])));
ready
construct
result = construct(MyClass, [1,2,3])
ready

Revisions

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