isDate - duck typing vs. instanceof

JavaScript performance comparison

Revision 2 of this test case created by Nige White

Preparation code

<script>
  var obj0 = new Date(),
      obj1 = {
    a: 5,
    b: 7
      },
      obj2 = new Date(2009, 0, 5),
      obj3 = 8;
</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
duck typing
!!(obj0 && obj0.getTimezoneOffset && obj0.setUTCFullYear)
pending…
instanceof
obj0 instanceof Date
pending…
toString
Object.prototype.toString.call(new Date()) === "[object Date]"
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