isDate - duck typing vs. instanceof (v2)

Revision 2 of this benchmark created by Nige White on


Description

This test is motivated by the use of duck typing in the current underscore.js implementation for _.isType() functions.

Preparation HTML

<script>
  var obj0 = new Date(),
      obj1 = {
    a: 5,
    b: 7
      },
      obj2 = new Date(2009, 0, 5),
      obj3 = 8;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
duck typing
!!(obj0 && obj0.getTimezoneOffset && obj0.setUTCFullYear)
ready
instanceof
obj0 instanceof Date
ready
toString
Object.prototype.toString.call(new Date()) === "[object Date]"
ready

Revisions

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