jQuery.each() vs for loop test

Benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

<script>
  var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ,11 ,12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
For Loop
function forLoop() {
  var count = 0;
  for (var f = 0; f < arr.length; ++f) {
    count += arr[f];
  }
  return count;
}
ready
jQuery.each()
function eachLoop() {
  var count = 0;
  $.each(arr, function(j, val) {
    count += val;
  }
  return count;
}
ready

Revisions

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