jquery selector speed id vs class index

JavaScript performance comparison

Revision 101 of this test case created

Preparation code

<div id="container">
  <ul>
    <li id="byID">1</li>
    <li class="unique_class">2.1</li>
    <li class="unique_class">2.2</li>
    <li class="unique_class">2.3</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.1
  • 2.2
  • 2.3
  • 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
$('#target')
$('#byID').html('1');
pending…
$('.target')
$('.unique_class').html('2');
pending…
$('.target').first()
$('.multi_class').first().html('3');
pending…
$("*")
$("*").Text();
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