FOR LOOPS test (v4)

Revision 4 of this benchmark created on


Description

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

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

var myArray = ['a', 'b', 'c', 'd'];

Test runner

Ready to run.

Testing in
TestOps/sec
for/in loop
var g_str = '';
for (var i in myArray) {
g_str+=myArray[i];
}
ready
for loop (no caching)
var g_str = '';
for (var i = 0; i < myArray.length; i++) {
g_str+=myArray[i];
}
ready
for loop (with caching)
var g_str = '';
for (var i = 0, l = myArray.length; i < l; i++) {
g_str+=myArray[i];
}
ready
jQuery.each (for comparison)
var g_str='';
jQuery.each(myArray, function(index, elem) {
    g_str += elem;
});
ready
es5 forEach
var g_str = '';
myArray.forEach(function(elem){
  g_str += elem;
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.