Array Iteration

JavaScript performance comparison

Revision 3 of this test case created by Bergi

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…
n-1 to 0 backwards
for (var i = arr.length; i-- > 0; ){
}
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:

0 comments

Add a comment