new array vs literal

JavaScript performance comparison

Revision 7 of this test case created by Don

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
new Array(length)
var newArray = new Array(500000)

for (var i = 0; i < 500000; ++i) {
    newArray[i] = i;
}
pending…
new Array()
var newArray = new Array();

for (var i = 0; i < 500000; ++i) {
    newArray[i] = i;
}
pending…
array literal w/length
var array = [];
array.length = 500000;

for (var i = 0; i < 500000; ++i) {
    array[i] = i;
}
pending…
array literal
var array = [];

for (var i = 0; i < 500000; ++i) {
    array[i] = i;
}
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:

0 comments

Add a comment