forEach vs. jQuery .each (v5)

Revision 5 of this benchmark created on


Description

This test compares speeds from ECMAscript5 (262) Array.prototype.forEach vs jQuery .each method and standard for..in, for methods.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var arr = [],
      loop = 5000;
  
  while (loop--) {
   arr[loop] = loop;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
each()
$.each(arr, function(i, v) {
 v = v;
});
ready
forEach()
arr.forEach(function(v, i) {
 v = v;
});
ready
for..in
for (var i in arr) {
 (function(x) {
  x = x;
 })(arr[i]);
}
ready
for
for (var i = 0; i < arr.length; i++) {
 (function(x) {
  x = x;
 })(arr[i]);
}
ready

Revisions

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