Jquery each vs Underscore each vs For loops (v83)

Revision 83 of this benchmark created by for on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js">
</script>

Setup

var each, lettersA, lettersB, pushInto;
    each = function(array, fn) {
      var len, z;
      z = 0;
      len = array.length;
      while (z < len) {
        fn.call(null, array[z]);
        z++;
      }
    };
    lettersA = [];
    lettersB = ['a', 'b', 'c', 'd', 'e'];
    pushInto = function(val) {
      lettersA.push(val);
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Jquery each
each(lettersB, pushInto);
ready
Underscore each
var len, z;
len = lettersB.length;
z = 0;

while (z < len) {
  lettersA.push(z);
  z++;
}
ready
For normal
var len, z;
len = lettersB.length;
z = 0;
while (z < len) {
  pushInto(lettersB[z]);
  z++;
}
ready

Revisions

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