for vs while

JavaScript performance comparison

Revision 2 of this test case created by Jongmin Kim

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
do while
function createArray(n) {
    let arr = [];
    for (let i = 0; i < n; i++) {
        arr.push(i)
    }
    return arr;
}

var arr = createArray(1000000);

var a = [];
var i = 0;
do {
   a.push(arr[i] + 1);
   i++;
}
while (i < arr.length)
pending…
for of
function createArray(n) {
    let arr = [];
    for (let i = 0; i < n; i++) {
        arr.push(i)
    }
    return arr;
}

var arr = createArray(1000000);

var a = [];
for (const b of arr) {
  a.push(b + 1);
}
pending…
for loop
function createArray(n) {
    let arr = [];
    for (let i = 0; i < n; i++) {
        arr.push(i)
    }
    return arr;
}

var arr = createArray(1000000);

var a = [];
for (let i = 0; i < arr.length; i++) {
  a.push(arr[i] + 1);
}
pending…
while
function createArray(n) {
    let arr = [];
    for (let i = 0; i < n; i++) {
        arr.push(i)
    }
    return arr;
}

var arr = createArray(1000000);

var a = [];
var i = 0;
while (i < arr.length) {
  a.push(arr[i] + 1);
  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.

0 Comments