array initialisation

JavaScript performance comparison

Revision 2 of this test case created

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
concat
var myArray = [true];
var desiredLength = 200000;
while (myArray.length < desiredLength) {
  myArray = myArray.concat(myArray);
}
if (myArray.length > desiredLength) {
  myArray.splice(desiredLength);
}
pending…
normal
var count = 200000;
var myArr = [];

myArr.length = count;
for (var i = 0; i < count; i++) {
  myArr[i] = true;
}
pending…
push
var count = 200000;
var myArr = [];
for (var i = 0; i < count; i++) {
  myArr.push(true);
}
pending…
push-20
var count = 200000;
var myArr = [];
for (var i = 0; i < count; i += 20) {
  myArr.push(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
}
pending…
splice
var count = 200000;
var myArr = [];
for (var i = 0; i < count; ++i) {
  myArr.splice(i, 1, true);
}
pending…
splice-20
var count = 200000;
var myArr = [];
for (var i = 0; i < count; ++i) {
  myArr.splice(i, 20, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
}
pending…
setLength-splice
var count = 200000;
var myArr = [];
myArr.length = count;
for (var i = 0; i < count; ++i) {
  myArr.splice(i, 1, true);
}
pending…
setLength-splice-20
var count = 200000;
var myArr = [];
myArr.length = 20;
for (var i = 0; i < count; ++i) {
  myArr.splice(i, 20, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
}
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