jQuery Selector Perf - Selector speed

JavaScript performance comparison

Revision 115 of this test case created

Preparation code

<div id="box">
  <p class="pclass">
    Hi
  </p>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js">
</script>
<script>
  $(function() {

    //add a bunch of other non p elements
    var ind = 0;
    var iterations = 1000;
    var htmls = "";
    while (iterations--) {
      htmls += "<a href='#' id=x=link-" + ind + "</a>\n";
      ind++;
    }
    $('#box').parent().append(htmls);

    console.log('hi')
  });
</script>

Preparation code output

Hi

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
1. $('#box p');
$('#box p');
pending…
2. $('#box').children('p');
$('#box').children('p');
pending…
3. $('#box').find('p');
$('#box').find('p');
pending…
4. $('p');
$('p');
pending…
5. $('#box p.pclass');
$('#box p.pclass');
pending…
6. $('#box').children('p.pclass');
$('#box').children('p.pclass');
pending…
7. $('#box').find('p.pclass');
$('#box').find('p.pclass');
pending…
8. $('p.pclass');
$('p.pclass');
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