jquery selector speed id vs class index

JavaScript performance comparison

Revision 98 of this test case created by

Preparation code

<div id="container">
  <ul>
    <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="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

    

Preparation code output

<div id="container"> <ul> <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>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
$('#target')
$('#byID').html('1');
pending…
$('.target') only 1 class on page
$('.unique_class').html('2');
pending…
$('.target').first()
$('.multi_class').first().html('3');
pending…
$('.target:eq(1)')
$('.multi_class:eq(1)').html('4');
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.

0 Comments