jQuery.each vs. alternatives (v41)

Revision 41 of this benchmark created on


Description

Each comparisons

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.each
var a = $('*').get(),
    e;

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

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

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

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

while (i--) {
  e = $(a[i]);
}
ready
jQuery.fn.each
$('*').each(function(i) {
  e = $(this);
});
ready
Native foreach
var a = $('*').get(),
    e = a.length;
a.forEach(function (item) {
    e = $(item);
});
ready

Revisions

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