type detection

Benchmark created by Rick Waldron on


Preparation HTML

<script>
  var subject = [1, 2, 3, 4, 5],
      toString = Object.prototype.toString;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.prototype.toString.call
(Object.prototype.toString.call(subject) === "[object Array]")
ready
duck typing
(typeof subject === "object" && "join" in subject && "length" in subject && typeof subject.length === "number")
ready
toString
(toString.call(subject) === "[object Array]")
ready

Revisions

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