instanceof performance (v20)

Revision 20 of this benchmark created on


Setup

function Test()
    {
    this.property = true;
    }
    
    Test.prototype = {
       constructor: Test
    }
    
    function Test2()
    {
    }
    Test2.prototype = {
       constructor: Test2
    }
    
    var arr = [], ts2 = [];
    var result;
    for(var i = 0; i < 1000; i++) {
    arr.push(new Test());
        ts2.push(new Test2());
    }

Test runner

Ready to run.

Testing in
TestOps/sec
instanceof success
for(var i = 0; i < 1000; ++i)
{
var t = arr[i];
result = t instanceof Test;
}
ready
constructor name success
for(var i = 0; i < 1000; ++i)
{
var t = arr[i];
result = t.constructor.name === 'Test';
}
ready
instanceof fail
for(var i = 0; i < 1000; ++i)
{
var t = ts2[i];
result = t instanceof Test;
}
ready
constructor name fail
for(var i = 0; i < 1000; ++i)
{
var t = ts2[i];
result = t.constructor.name === 'Test';
}
ready
constructor success
for(var i = 0; i < 1000; ++i)
{
var t = arr[i];
result = t.constructor === Test;
}
ready
constructor fail
for(var i = 0; i < 1000; ++i)
{
var t = ts2[i];
result = t.constructor === Test;
}
ready

Revisions

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