typeof function vs instanceof

Benchmark created by Andreas Göbel on


Description

This testcase compares the performance when checking if a variable (argument) is a function. typeof foo === 'function' vs. foo instanceof Function.

Preparation HTML

<script>
  var foo = function() {};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
typeof
if (typeof foo === 'function') {}
ready
instanceof
if (foo instanceof Function) {}
ready

Revisions

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