instanceOf Array vs Array.isArray()

JavaScript performance comparison

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
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…
IsArray C
Array.isArray(C) ? true : false;
pending…
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…

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