JS: Array.reverse() vs. for and while loops (v37)

Revision 37 of this benchmark created on


Description

Checking performance of Array.reverse() vs custom loops.

See http://stackoverflow.com/questions/5276953/what-is-the-most-efficient-way-to-reverse-an-array-in-javascript.

Also see http://jsperf.com/forloop-vs-reverse-while-loop-and-array-reverse/9.

Preparation HTML

<script>
    var array = [];
    for(var i=0; i<10000; i++) {
       array.push(i);
    }
    var length = array.length;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
fo
var count = array.length;
for(var i = 0; i < count; i++){
var a = i;
}
ready
while
var i = 0;
var count = array.length;
while (i < count)
{
    var a = i;
    i++;
}
ready

Revisions

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