Createating small array with known length using"[]" or "new Array(ARR_SIZE)" performance

JavaScript performance comparison

Test case created by olegolegoleg

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Creating array with "new Arry(5)"
// Create array.
const arrLength = 5;
const arrNew = new Array(arrLength );

// Test: fill with values.
for(let i = 0; i < arrLength; i++) {
	arrNew[i] = i + i;
}

// Check result just in case of VM optimizations.
const targetSum = 20;
let resultSum = 0;
for(let i = 0; i < arrLength; i++) {
	resultSum+= arrNew[i];
}
if (resultSum !== targetSum) {
	throw new Error("Result sum mistmatch!");
}
pending…
Creating array with "[]"
// Create array.
const arrLength = 5;
const arrNew = [];

// Test: fill with values.
for(let i = 0; i < arrLength; i++) {
	arrNew[i] = i + i;
}

// Check result just in case of VM optimizations.
const targetSum = 20;
let resultSum = 0;
for(let i = 0; i < arrLength; i++) {
	resultSum+= arrNew[i];
}
if (resultSum !== targetSum) {
	throw new Error("Result sum mistmatch!");
}
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.

0 Comments