===+obj.length vs typeof number (v2)

Revision 2 of this benchmark created on


Description

is obj.length === +obj.length fast?

Preparation HTML

<script>
var ary = [];
for(var i=0;i<10000;i++){
if(i%5===0) {
ary.push('nope');
} else {
ary.push(i);
}
}

function comp1(obj){
if (obj.length === +obj.length){
   return true;
}
}

function comp2(obj){
if (typeof obj.length==='number'){
   return true;
}
}

function doComp1(){
   comp1(ary);
   comp1({});
}

function doComp2(){
   comp2(ary);
   comp2({});
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
+length
doComp1()
ready
typeof
doComp2()
ready

Revisions

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