Browser Diet - jQuery.each vs. for loop (v33)

Revision 33 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  var a = $('*').get(),
      e;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.each
var newarr = [];
$.each(a, function() { 
e = this; 
newarr.push(e);
})
ready
for loop
var newarr = [];
var len = a.length;
for (var i = 0; i < len; i++) { 
newarr.push(a[i]); 
}
ready
for without caching
var newarr = [];
for (var i = 0; i < a.length; i++) { 
newarr.push(a[i]); 
}
ready
alternative for loop
var newarr = [];
for (var i in a) {
newarr.push(a[i]);  
}
ready
reverse for
var newarr = [];
for (var i = a.length; i--;) {
newarr.push(a[i]);  
}
ready
while reverse
var i = a.length;
var newarr = [];
while(i){
newarr.push(a[--i]);  
}
ready

Revisions

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