while-vs-for (v4)

Revision 4 of this benchmark created on


Setup

// both
    
    // var arr = [0,1,2,3,4,5,6,7,8,9];
    // var arr = [0,1,2];
    var arr = [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9];
    
    var obj = {one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, zero: 0};
    var foo = 0;
    
    // while
    
    var index = -1,
        length = obj.length

Test runner

Ready to run.

Testing in
TestOps/sec
while
while (++index < length) {
    foo++
}
ready
for
for (var i = 0, l = length; i < l; i++) {
   foo++
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.