new array (new Array()) vs literal array ([])

JavaScript performance comparison

Revision 13 of this test case created by fcanache

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…
array literal with preset index
var array = [], i=0;

for (; i < 500000; ++i) {
    array[i] = i;
}
pending…
array literal with preset index and push
var array = [], i=0;

for (; i < 500000; ++i) {
    array.push(i);
}
pending…
new Array() with preset index
var newArray = new Array(), i=0;

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

for (; i < 500000; ++i) {
    newArray[i] = i;
}
pending…
array literal with length and preset index
var array = [], i=0;
array.length = 500000

for (; i < 500000; ++i) {
    array[i] = i;
}
pending…
new Array() with preset index and push
var newArray = new Array(), i=0;

for (; i < 500000; ++i) {
    newArray.push(i);
}
pending…
new Array() with push
var newArray = new Array();

for (var i = 0; i < 500000; ++i) {
    newArray.push(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