new array vs literal (v19)

Revision 19 of this benchmark created on


Setup

var orig = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

Test runner

Ready to run.

Testing in
TestOps/sec
Array Literal
var newArray = [];
for (var i=0; i<16; ++i)
newArray[i] = 1;
ready
new Array()
var newArray = new Array(16);
for (var i=0; i<16; ++i)
newArray[i] = 1;
ready
[0,...]
var newArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (var i=0; i<16; ++i)
newArray[i] = 1;
ready
[].concat
var newArray = [].concat(orig);
for (var i=0; i<16; ++i)
newArray[i] = 1;
ready
slice(0)
var newArray = orig.slice(0);
for (var i=0; i<16; ++i)
newArray[i] = 1;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.