instanceOf Array vs Array.isArray()
JavaScript performance comparison
Info
Comparison between the different ways of checking if a value is an array.
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]
],
D = 16,
E = { foo: 'bar' },
F = true,
G = null;
var isArray = Array.isArray,
toString = Object.prototype.toString;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
Instance of Array A |
|
pending… |
IsArray A |
|
pending… |
Constructor of A |
|
pending… |
toString A |
|
pending… |
Instance of Array B |
|
pending… |
IsArray B |
|
pending… |
Constructor of B |
|
pending… |
toString B |
|
pending… |
Instance of Array C |
|
pending… |
IsArray C |
|
pending… |
Constructor of C |
|
pending… |
toString C |
|
pending… |
Instance of Array D |
|
pending… |
IsArray D |
|
pending… |
Constructor of D |
|
pending… |
toString D |
|
pending… |
Instance of Array E |
|
pending… |
IsArray E |
|
pending… |
Constructor of E |
|
pending… |
toString E |
|
pending… |
Instance of Array F |
|
pending… |
IsArray F |
|
pending… |
Constructor of F |
|
pending… |
toString F |
|
pending… |
Instance of Array G |
|
pending… |
IsArray G |
|
pending… |
Constructor of G |
|
pending… |
toString G |
|
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. Here’s a list of current revisions for this page:
- Revision 1: published by Brian Jemilo II
- Revision 2: published by Artur Raczyński
- Revision 3: published
- Revision 4: published
- Revision 5: published by Ezra Olubi
- Revision 6: published by Nikos M.
- Revision 7: published by Itsik Avidan
- Revision 8: published by me
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 15: published
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published by ZAlexz
- Revision 20: published by dalisoft
- Revision 21: published by dalisoft
- Revision 22: published by Mario DE WEERD
0 comments
Comment form temporarily disabled.