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

Revision 6 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
$el = $elems.eq(0);
ready
.get
$el = $($elems.get(0));
ready
[]
$el = $($elems[0]);
ready
.slice
$el = $elems.slice(0, 1);
ready
replacing $()[..]
$el = $([1]);
($el.context = $el[0] = $elems[0]);
ready

Revisions

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