jQuery .eq vs .get or [] inside $() (v8)

Revision 8 of this benchmark created on


Description

Keep in mind, of course, that .eq is revertable with .end because .pushStack is used internally...

Preparation HTML

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

<script>
  // Create a whole bunch of elements for iteration.
  var $elems = $('<div/>').append(Array(1000).join('<span/>')).children();
  var $el;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
.eq
$elems.each(function(idx) {
    var t = $elems.eq(idx);
});
ready
$(this)
$elems.each(function() {
    var t = $(this);
});
ready
elem
$elems.each(function(idx, elem) {
    var t = $(elem);
});
ready

Revisions

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