jQuery.each vs. for loop (v281)

Revision 281 of this benchmark created on


Description

test for jquery latest

Preparation HTML

<script src="//code.jquery.com/jquery-2.0.3.min.js"></script>

Setup

var a = [],
      e,
      arrayLength;
    for (var j = 0; j < 10000; j++) {
      a.push(Math.floor(Math.random() * 1000))
    }
    arrayLength = a.length;

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.each
$.each(a, function(i, val) {
  e = val;
});
ready
for loop
for (var i = 0; i < arrayLength; i++) {
  e = a[i];
};
ready
for without caching
for (var i = 0; i < arrayLength; i++) {
  e = a[i];
};
ready
alternative for loop
for (i in a) {
  e = a[i];
};
ready
reverse for
for (var i = arrayLength; i--;) {
  e = a[i]
}
ready
Native each method
a.forEach(function(v, i) {
  e = v;
});
ready

Revisions

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