Array Iteration

JavaScript performance comparison

Test case created by Sam

Info

Compare iterating forward or backwards of an array

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var arr = [];
    for (var i = 0; i < 10000; ++i) {
      arr.push(1);
    }
   
};
</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
forwards
for (var i = 0; i < arr.length; ++i) {;
}
pending…
backwards
for (var i = arr.length; i > 0; --i) {;
}
pending…
Hard Coded Forward
for (var i = 0; i < 10000; ++i) {;
}
pending…
Cached Forward Iteration
for(var i=0, c=arr.length; i<c; 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:

1 comment

Gerry commented :

any idea what is happening with FF 9 and 10? Are these misreads for the test or is it really so much faster that it is 'off the charts'?

Add a comment