instanceof performance (v17)

Revision 17 of this benchmark created by DrSlump on


Setup

function Test()
    {
    this.property = true;
    }
    
    function 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
property success
for(var i = 0; i < 1000; ++i)
{
var t = arr[i];
result = t.property;
}
ready
instanceof fail
for(var i = 0; i < 1000; ++i)
{
var t = ts2[i];
result = t instanceof Test;
}
ready
property fail
for(var i = 0; i < 1000; ++i)
{
var t = ts2[i];
result = t.property;
}
ready
in
for(var i = 0; i < 1000; ++i)
{
var t = arr[i];
result = 'property' in t;
}
ready
in fail
for(var i = 0; i < 1000; ++i)
{
var t = ts2[i];
result = 'property' in t;
}
ready

Revisions

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