jquery selector speed id vs class index

JavaScript performance comparison

Revision 110 of this test case created

Preparation code

<div id="container">
  <ul class="list">
    <li id="byID">1</li>
    <li class="unique_class">2</li>
    <li class="multi_class">3</li>
    <li class="multi_class">4</li>
  </ul>
</div><script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 

Preparation code output

  • 1
  • 2
  • 3
  • 4

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
$('#container li')
$('#container li');
pending…
$('#container .unique_class')
$('#container .unique_class');
pending…
$('#container li.unique_class')
$('#container li.unique_class');
pending…
$('#container').find('li')
$('#container').find('li');
pending…
$('#container').find('.unique_class')
$('#container').find('.unique_class');
pending…
$('#container').find('li.unique_class')
$('#container').find('li.unique_class');
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