typeof vs instanceof Object (v3)

Revision 3 of this benchmark created by PlayMyCode on


Preparation HTML

<script>
  x = 52;
  n = 1000;
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
typeof
var r = 0;
for (var i = 0; i < n; i += 1)
{
    if (typeof x === 'number')
    {
        r += 1;
    }
}
 
ready
instanceof
var r = 0;
for (var i = 0; i < n; i += 1)
{
    if (x instanceof Number)
    {
        r += 1;
    }
}
ready

Revisions

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

  • Revision 3: published by PlayMyCode on
  • Revision 5: published by pcowdogg on