instanceof vs typeof (v14)

Revision 14 of this benchmark created by Dylan on


Preparation HTML

<script>
  var a = [];
  var f = function() {};
  var x;
  var slit = "i am literal string";
  var sobj = new String("i am a string object");
  var toString = Object.prototype.toString;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
array - instanceof
x = a instanceof Array;
ready
array - constructor
x = a != null && a.constructor === Array
ready
function - instanceof
x = f instanceof Function;
ready
function - constructor
x = f.constructor === Function;
ready
string - toString
x = toString.call(slit) == '[object String]';
y = toString.call(sobj) == '[object String]';
ready
string - instanceOf
x = slit instanceof String;
y = sobj instanceof String;
ready
string - typeof
x = typeof slit == 'string';
y = typeof sobj == 'string';
ready
func typeof
x = typeof f == 'function'; 
ready
x = toString.call(slit) == '[object Function]';
ready

Revisions

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