instanceOf Array vs Array.isArray()

JavaScript performance comparison

Revision 33 of this test case created by Brian Jemilo II

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var A = [1, 2, 3, 4, 5],
  B = ['a', 'b', 'c', 'd', 'e'],
  C = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]];

};
</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
Instance of Array A
A instanceof Array ? true : false;
pending…
Instance of Array B
B instanceof Array ? true : false;
pending…
Instance of Array C
C instanceof Array ? true : false;
pending…
IsArray A
Array.isArray(A) ? true : false;
pending…
IsArray B
Array.isArray(B) ? true : false;
pending…
IsArray C
Array.isArray(C) ? true : false;
pending…
Constructor of A
A.constructor === Array ? true : false;
pending…
Constructor of B
B.constructor === Array ? true : false;
pending…
Constructor of C
C.constructor === Array ? true : false;
pending…
A toString constructor comparison
A.constructor.toString() === Array().constructor.toString();
pending…
B toString constructor comparison
B.constructor.toString() === Array().constructor.toString();
pending…
C toString constructor comparison
C.constructor.toString() === Array().constructor.toString();
pending…
A Bitwise
!!~A.constructor.toString().indexOf('Array');
pending…
B Bitwise
!!~B.constructor.toString().indexOf('Array');
pending…
C Bitwise
!!~C.constructor.toString().indexOf('Array');
pending…
A Prototype
Object.prototype.toString.call(A) === '[object Array]';
pending…
B Prototype
Object.prototype.toString.call(B) === '[object Array]';
pending…
C Prototype
Object.prototype.toString.call(C) === '[object Array]';
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