FOR LOOPS test

JavaScript performance comparison

Revision 8 of this test case created

Info

Difference between for/in, classical for loop and classical loop with caching.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var myArray = [3, 1, 4, 1, 5, 9, 2, 6];
};
</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
for/in loop
var sum = 0,
    l = myArray.length;
for (var i = 0; i < l; i++) {
    sum += myArray[i];
}
pending…
for loop (no caching)
var sum = 0;
for (var i = 0; i < myArray.length; i++) {
    sum += myArray[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:

0 comments

Add a comment