jQuery Multiple Selector Performance Problems

JavaScript performance comparison

Test case created by Justin Seger

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
  var jq142 = jQuery.noConflict();
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script>
  var jq143 = jQuery.noConflict();
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
  var jq151 = jQuery.noConflict();
</script>
<script src="https://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 + '">';

      for ( var i = 0; i < 1000; i++ ) {
        html += '<div class="find"></div>';
      }

      html += '</div>';
    }
    document.write( html );
  </script>
  <input name='testinput' type='hidden' />
  <select name='testselect'><option>1</option><option>2</option></select>
</div>
<script>
  var $jq142 = jq142("body");
  var $jq143 = jq143("body");
  var $jq151 = jq151("body");
  var $jqgit = jqgit("body");
</script>
    

Preparation code output

<script> var jq142 = jQuery.noConflict(); </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script> var jq143 = jQuery.noConflict(); </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <script> var jq151 = jQuery.noConflict(); </script> <script src="https://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 + '">'; for ( var i = 0; i < 1000; i++ ) { html += '<div class="find"></div>'; } html += '</div>'; } document.write( html ); </script> <input name='testinput' type='hidden' /> <select name='testselect'><option>1</option><option>2</option></select> </div> <script> var $jq142 = jq142("body"); var $jq143 = jq143("body"); var $jq151 = jq151("body"); var $jqgit = jqgit("body"); </script>

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
input,select - 1.4.2
$jq142.find("input,select");
pending…
input,select - 1.4.3
$jq143.find("input,select");
pending…
input,select - 1.5.1
$jq151.find("input,select");
pending…
input,select - GIT
$jqgit.find("input,select");
pending…
input then add() select - GIT
$jqgit.find("input").add("select");
pending…
input only - GIT
$jqgit.find("input");
pending…
select only - GIT
$jqgit.find("select");
pending…
input then select - GIT
$jqgit.find("input");
$jqgit.find("select");
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