typeof vs instanceof (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
  var o = {
   "a": 1,
   "b": 2,
   "c": 3
  };
  
  var a = [1, 2, 3];
  
  var tos = Object.prototype.toString;
  
  var apop = Array.prototype.pop;
  var A = [];
  var aproto = A.__proto__;
  
  var aproto2 = A.constructor.prototype;
  
  var r;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
typeof
r = (typeof o == 'object');
ready
instanceof
r = (a instanceof Array);
ready
isarray
r = (tos.call(a) === '[object Array]');
ready
__proto__
r = (a.__proto__ === aproto);
ready
constructor.prototype
r = (a.constructor.prototype === aproto2);
ready
pop
r = (a.pop === apop);
ready
index0
r = ((typeof a !== 'string') && (a[0] !== undefined));
ready

Revisions

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