isDate - duck typing vs. instanceof

Benchmark created by Andi 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); !! (obj1 && obj1.getTimezoneOffset && obj1.setUTCFullYear); !! (obj2 && obj2.getTimezoneOffset && obj2.setUTCFullYear); !! (obj3 && obj3.getTimezoneOffset && obj3.setUTCFullYear);
ready
instanceof
obj0 instanceof Date;
obj1 instanceof Date;
obj2 instanceof Date;
obj3 instanceof Date;
ready

Revisions

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