jQuery siblings vs parent.find vs find(~)

JavaScript performance comparison

Test case created by Calvein

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<ul>
  <li>0
  <li>1
  <li>2
  <li>3
  <li>4
  <li>5
  <li>6
  <li>7
  <li>8
  <li>9
</ul>
<script>
Benchmark.prototype.setup = function() {
    var $li = $('li:first-child')
};
</script>

Preparation code output

  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
siblings
$li.siblings('li')
pending…
parent
$li.parent().find('li:not(:nth-child(' + $li.index() + 1 + '))')
pending…
find
$li.find('~ li')
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment