jquery selector speed

JavaScript performance comparison

Revision 54 of this test case created

Info

Removing results-skewing tests which aren't comparable to the others - keeping only searches on class

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  $(document).ready(function() {
    var $pop = $('#parent'),
        i = 5000;
    while (i--)
    $pop.append("<li class='target' an_attribute='target'>" + i + "</li>");
    var val;
  });
</script>
<div id='grandparent'>
  <ul id='parent'>
  </ul>
</div>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
$('.target')
val = $('.target');
pending…
$('li.target')
val = $('li.target');
pending…
$('[an_attribute=target]')
val = $('[an_attribute=target]');
pending…
getElementsByClassName
val = $(document.getElementsByClassName('target'));
pending…
Find and Filter
val = $.find('li').filter('.target');
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