FOR LOOPS test

JavaScript performance comparison

Revision 16 of this test case created

Info

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

Preparation code

<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var myArray = ['a', 'b', 'c', 'd'];
};
</script>

Preparation code output

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
for (var i in myArray) {}
pending…
for loop (no caching)
for (var i = 0; i < myArray.length; i++) {}
pending…
for loop (with caching)
for (var i = 0, l = myArray.length; i < l; i++) {}
pending…
jQuery.each (for comparison)
jQuery.each(myArray, function(index, elem) {});
pending…
No counter
for (var i = myArray.length; i--;){}
pending…
declaration before loop
var i = 0, l = myArray.length;
for (; i < l; 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