instanceof vs typeof (v15)

Revision 15 of this benchmark created 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.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
func - toString
x = toString.call(slit) == '[object Function]';
ready
array - Array.isArray
x = Array.isArray(a)
ready

Revisions

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