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]];
};
</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… |
Instance of Array B |
|
pending… |
Instance of Array C |
|
pending… |
IsArray A |
|
pending… |
IsArray B |
|
pending… |
IsArray C |
|
pending… |
Constructor of A |
|
pending… |
Constructor of B |
|
pending… |
Constructor of C |
|
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
0 comments