jQuery.each vs. for loop (v219)

Revision 219 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js">
</script>
<script src="//underscorejs.org/underscore.js">
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  var a = $('*').get(),
      e;
</script>
<script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js">
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.each
$.each(a, function() {
  e = this;
});
ready
for loop
var len;
for (var i = 0, len = a.length; i < len; i++) {
  e = a[i];
};
ready
for without caching
for (var i = 0; i < a.length; i++) {
  e = a[i];
};
ready
alternative for loop
for (var i in a) {
  e = a[i];
};
ready
foreach
a.forEach(function(elem) {
  e = elem;
});
ready
knockout arrayForEach
ko.utils.arrayForEach(a, function(item) {
  e = item;
});
ready
angular
angular.forEach(a, function(item) {
  e = item;
});
ready
underscore
_.forEach(a, function(item) {
  e = item;
});
ready
While Loop
var i = 0;
var aLength = a.length;
while (i < aLength) {
  e = a[i];
  i++
};
ready

Revisions

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