jQuery Multiple Selector Performance Problems

JavaScript performance comparison

Revision 6 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script src="http://code.jquery.com/jquery-git.js"></script>
<script>
  var jqgit = jQuery.noConflict();
</script>
<div class="test" id="test">
  <script>
    var html = "";
for ( var i = 0; i < 100; i++ ) {
        html += '<div class="find"></div>';
      }

    for ( var j = 0; j < 20; j++ ) {
      html += '<div id="bigdiv' + j + '">';

      

      html += '</div>';
    }
    document.write( html );
  </script>
  <input name='testinput' type='hidden' />
  <select name='testselect'><option>1</option><option>2</option></select>
</div>
    

Preparation code output

<div class="test" id="test"> <input name='testinput' type='hidden' /> <select name='testselect'><option>1</option><option>2</option></select> </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
Two Selectors
$("#bigdiv0").remove();
$("#bigdiv1").remove();
$("#bigdiv2").remove();
$(".find").remove();
pending…
One Selector
$("#bigdiv0, #bigdiv1, #bigdiv2 , .find").remove();
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