forloop vs reverse while loop and array reverse

Benchmark created by Dan Masquelier on


Description

I know that reverse while looping in javascript is faster than for looping, but if order is to be maintained, would rev-while looping then reversing the array be faster or would the traditional for loop out perform this combo?

Preparation HTML

<script>
  var temp = [];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for loop
for (var i = 0; i < 10000; i++) {
  temp.push(i + 1);
}
console.log(temp);
ready
while loop with reverse for order
var i = 10000;
while (i--) {
  temp.push(i + 1);
}
temp.reverse();
console.log(temp);
ready

Revisions

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