jQuery.each vs. alternatives (v151)

Revision 151 of this benchmark created on


Description

Each comparisons

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var b = $('*'),
      e;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.each
var a = b.get();

jQuery.each(b, function() {
 e = $(this);
});
ready
for loop
var a = b.get(),
    len = a.length;

for (var i = 0; i < len; i++) {
 e = $(a[i]);
};
ready
while loop
var a = b.get(),
    i = a.length - 1;

while (e = a[i--]) {
 $(e)
};
ready
alternative for loop
var a = b.get();

for (var i in a) {
 e = $(a[i]);
};
ready
reverse for
var a = b.get();

for (var i = a.length; i--;) {
 e = $(a[i]);
}
ready
While 2
var a = b.get(),
    i = a.length;

while (i--) {
 e = $(a[i]);
}
ready
jQuery.fn.each
b.each(function(i){
 e = $(this);
});
ready
jQuery.each 2
$.each(b, function() {
 e = $(this);
});
ready

Revisions

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