isDate - duck typing vs. instanceof

JavaScript performance comparison

Test case created by Andi

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); !! (obj1 && obj1.getTimezoneOffset && obj1.setUTCFullYear); !! (obj2 && obj2.getTimezoneOffset && obj2.setUTCFullYear); !! (obj3 && obj3.getTimezoneOffset && obj3.setUTCFullYear);
pending…
instanceof
obj0 instanceof Date;
obj1 instanceof Date;
obj2 instanceof Date;
obj3 instanceof 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