Creating a new Array

JavaScript performance comparison

Revision 6 of this test case created by tomByrer

Info

v6: Renamed tests; there were 3 "array literal", & grouped the tests. All quotes are now single. Array.length(5). Also removed the .push tests; which have been already done. Added a few more tricks.

Note: there are good reasons to use literal array syntax other disregarding speed.

This test assume dense arrays (eg no skipping array indexes).

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
literal plain
var test = [];
test[0]='foo'; test[1]='bar'; test[2]='baz'; test[3]='qux'; test[4]='zed';
pending…
literal; length
var test = [];
test.length = 5;
test[0]='foo'; test[1]='bar'; test[2]='baz'; test[3]='qux'; test[4]='zed';
pending…
literal ,,,,
var test = [,,,,];
test[0]='foo'; test[1]='bar'; test[2]='baz'; test[3]='qux'; test[4]='zed';
// http://stackoverflow.com/a/4852089/1324588
pending…
literal filled
var test = ['foo', 'bar', 'baz', 'qux','zed'];
pending…
ctor
var test = new Array('foo', 'bar', 'baz', 'qux', 'zed');
pending…
Array()
var test = new Array();
test[0]='foo'; test[1]='bar'; test[2]='baz'; test[3]='qux'; test[4]='zed';
pending…
Array .length
var test = new Array();
test.length = 5;
test[0]='foo'; test[1]='bar'; test[2]='baz'; test[3]='qux'; test[4]='zed';
pending…
Array(length)
var test = new Array(5);
test[0]='foo'; test[1]='bar'; test[2]='baz'; test[3]='qux'; test[4]='zed';
pending…
Array(,,,,)
var test = new Array('','','','','');
test[0]='foo'; test[1]='bar'; test[2]='baz'; test[3]='qux'; test[4]='zed';
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