typeof vs constructor

JavaScript performance comparison

Revision 4 of this test case created by Gabriel

Preparation code

<script>
  var foo = function (){};
  var bar = 123;
  var baz = 'yey!';
  var qux = {};
  
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
typeof
typeof foo == 'function';
typeof bar == 'number';
typeof baz == 'string';
typeof qux == 'object';
pending…
constructor ==
foo.constructor == Function;
bar.constructor == Number;
baz.constructor == String;
qux.constructor == Object;
pending…
constructor ===
foo.constructor === Function;
bar.constructor === Number;
baz.constructor === String;
qux.constructor === Object;
pending…
constructor.name
foo.constructor.name === 'Function';
bar.constructor.name === 'Number';
baz.constructor.name === 'String';
qux.constructor.name === 'Object';
pending…
typeof ===
typeof foo === 'function';
typeof bar === 'number';
typeof baz === 'string';
typeof qux === 'object';
pending…
instanceof
foo instanceof Function;
bar instanceof Number;
baz instanceof String;
qux instanceof Object;
pending…

Compare results of other browsers

Revisions

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

0 Comments