jQuery Multiple Selector Performance Problems (v7)

Revision 7 of this benchmark created on


Preparation HTML

<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 j = 0; j < 20; j++ ) {
      html += '<div id="bigdiv' + j + '">a</div>';
    }
    document.write( html );

    var html = "";

    for ( var j = 0; j < 20; j++ ) {
      html += '<div id="bdiv' + j + '">a</div>';
    }
    document.write( html );
  </script>

</div>

Test runner

Ready to run.

Testing in
TestOps/sec
Two Selectors
for ( var j = 0; j < 100; j++ ) {
  $("#bigdiv"+j).remove();
}
ready
One Selector
var txt1 ='';
var var1 = '';

for ( var j = 0; j < 100; j++ ) {
   var1 = "'#bdiv" + j +"',";
   txt1 += var1;
}

$(txt1).remove();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.