Typeof-vs-toString-vs-instanceof

Benchmark created on


Description

test performance of type checks

Setup

var func = function() {}

Teardown


    var func = null
  

Test runner

Ready to run.

Testing in
TestOps/sec
typeof
var res;
for (var i = 0; i < 10000; i++) {
  res = typeof func === "function";
}
ready
toString
var res;
for (var i = 0; i < 10000; i++) {
  res = Object.prototype.toString.call(func) === "[object Function]";
}
ready
instanceof
var res;
for (var i = 0; i < 10000; i++) {
  res = func instanceof Function;
}
ready
constructor
var res;
for (var i = 0; i < 10000; i++) {
  res = func.constructor === Function;
}
ready

Revisions

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