for vs while loop

JavaScript performance comparison

Revision 21 of this test case created

Preparation code

<script>
  var foo = [1, 2, 3, 4, 5];
</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
for
for(var i=0 ;i<=foo.length;i++){

}
pending…
while
var i = foo.length;
while(i--){

}
pending…
JT for
var id, theNum
var prependId = 'testing'

for(var i = 0; true; i++){
    id = prependId + i
    if(id.slice(-1) < 500)  {
        theNum = id.slice(-1)
    } else {
        break
    }
}
pending…
JT While
var theNum
var prependId = 'testing'
var i = 0
var id = prependId + i

while (id.slice(-1) < 500) {
    theNum = id.slice(-1)
    i++
    id = prependId + 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. Here’s a list of current revisions for this page:

0 comments

Add a comment