FOR LOOPS test

JavaScript performance comparison

Revision 23 of this test case created

Info

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

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.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
do ... while (i--)
var i = myArray.length - 1
var x
do { x = myArray[i] } while (i--)
pending…
for loop (no caching)
var x
for (var i = 0; i < myArray.length; i++) { x = myArray[i] }
pending…
for loop (with caching)
var x
for (var i = 0, l = myArray.length; i < l; i++) { x = myArray[i] }
pending…
do ... while (--i)
var i = myArray.length - 1
var x
do { x = myArray[i] } while (--i >= 0)
 
pending…
while (--i)
var i = myArray.length
var x
while (--i >= 0) { x = myArray[i] }
pending…
while (i--)
var i = myArray.length
var x
while (i--) { x = myArray[i] }
pending…
for loop (no caching, ++i)
var x
for (var i = 0; i < myArray.length; ++i) { x = 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