instanceOf Array vs Array.isArray() vs toString

JavaScript performance comparison

Revision 6 of this test case created by Nikos M.

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…
ToString.call of A
toString.call(A) === '[object Array]' ? true : false
pending…
ToString.call of B
toString.call(B) === '[object Array]' ? true : false
pending…
ToString.call of C
toString.call(C) === '[object Array]' ? true : false
pending…
A.push && A.pop
A.push && A.pop ? true : false
pending…
B.push && B.pop
B.push && B.pop ? true : false
pending…
C.push && C.pop
C.push && C.pop ? true : false
pending…
A.prototype.push
A.__proto__.push ? true : false
pending…
B.prototype.push
B.__proto__.push ? true : false
pending…
C.prototype.push
C.__proto__.push ? 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