Underscore isArray vs Alternative isArray

Benchmark created by Nate Hunzaker on


Description

An analysis of tweaks to the Underscore.js isArray function.

Note: This test is a pretty pointless endeavor in hindsight.

Setup

var testArray = [1, 2, 3, 4];
    var toString = Object.prototype.toString;
    
    var underscoreMethod = Array.isArray || function(obj) {
      return toString.call(obj) == '[object Array]';
    };
    
    var proposedMethod = Array.isArray || (function() {
      return function(obj) {
        return toString.call(obj) == '[object Array]';
      };
    }());

Test runner

Ready to run.

Testing in
TestOps/sec
Underscore Method
underscoreMethod(testArray)
ready
Proposed Method
proposedMethod(testArray)
ready

Revisions

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

  • Revision 1: published by Nate Hunzaker on