repeat for vs array method2

JavaScript performance comparison

Revision 5 of this test case created

Preparation code

<script>

function tArray() {
return new Array(11).join("+");
}

function tPlusFor() {
var text = "";
for (var i = 0; i < 10; i++) {
  text += "+";
}
return text;
}


function tMinusFor() {
var text = "";
for (var i = 10; i > 0; i--) {
  text += "+";
}
return text;
}
function tPlusWhile() {
var text = "";
var i = 0;
while (i++ < 10) {
  text += "+";
}
return text;
}
function tMinusWhile() {
var text = "";
var i = 10;
while (i--) {
  text += "+";
}
return text;
}
function tPlusDoWhile() {
var text = "";
var i = 0;
do {
  text += "+";
} while (++i < 10);
return text;
}
function tMinusDoWhile() {
var text = "";
var i = 10;
do {
  text += "+";
} while (--i);
return text;
}

var l = 1e4;

while(l--){
    var a = tArray();
    var a = tPlusFor();
    var a = tMinusFor();
    var a = tPlusWhile();
    var a = tMinusWhile();
    var a = tPlusDoWhile();
    var a = tMinusDoWhile();
}
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Array
var a = tArray();
if( a.length !== 10 ) {
     die();
}
pending…
Plus For
var a = tPlusFor();
if( a.length !== 10 ) {
     die();
}
pending…
Minus For
var a = tMinusFor();
if( a.length !== 10 ) {
     die();
}
pending…
Plus While
var a = tPlusWhile();
if( a.length !== 10 ) {
     die();
}
pending…
Minus While
var a = tMinusWhile();
if( a.length !== 10 ) {
     die();
}
pending…
Plus Do while
var a = tPlusDoWhile();
if( a.length !== 10 ) {
     die();
}
pending…
Minus do while
var a = tMinusDoWhile();
if( a.length !== 10 ) {
     die();
}
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