Native Loop Performance (v2)

Revision 2 of this benchmark created on


Description

Testing which method of looping through an array with 285 items is fastest.

Preparation HTML

<script>
  var arr = [1, 2, 9]
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for()
for (var i = 0; i < arr.length; i++)
ready
for() caching length
for (var i = 0, length = arr.length; i < length; i++)
ready
while() acting like for()
var i = 0;
while (i < arr.length) {
 i++
}
ready
while() acting like for(), caching length
var i = 0,
    length = arr.length;
while (i < length) {
 i++
}
ready
while() in reverse
var length = arr.length;
while (length--)
ready

Revisions

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