typeof vs "in" object keyword

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var obj = { dev: 2114,
      ino: 48064969,
      mode: 33188,
      nlink: 1,
      uid: 85,
      gid: 100,
      rdev: 0,
      size: 527,
      blksize: 4096,
      blocks: 8,
      atime: "Mon, 10 Oct 2011 23:24:11 GMT",
      mtime: "Mon, 10 Oct 2011 23:24:11 GMT",
      ctime: "Mon, 10 Oct 2011 23:24:11 GMT" };
   
    var t = 0;
    var i = 0;
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
typeof
if( typeof obj["invalid"] === "undefined" ) {
    t++;
}
pending…
in
if( "invalid" in obj ) {
    i++;
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment