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

Benchmark created by "Cowboy" Ben Alman on


Description

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

(idea belongs to @getify)

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();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
.eq
elems.eq(0);
ready
.get
$(elems.get(0));
ready
[]
$(elems[0]);
ready

Revisions

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