jQuery 1.4.3 perf degrade

Benchmark created by Charles McNulty on


Description

This may still work in IE a couple of hundred elements (though very slowly), but when raising the amount of elements to around ~500, you'll probably already get the "Stop running script" alert.

Preparation HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>var a = jQuery.noConflict();</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>var b = jQuery.noConflict();</script>

<style>
input, select, ul, div {
    display: none;  
}
</style>

<div class="lonely">
    
</div>

<div id="items">
    
</div>


<script>
  var amt = 50;
  var $n;
  var $a_items = a('#items'),
      $b_items = b('#items');
  var elems = [];
  
  for (var i = 0; i < amt; i++) {
   elems.push('<ul><li>foo</li></ul>');
   elems.push('<div>hmm</div>');
   elems.push('<input type="hidden" name="hoo' + i + '" /> ')
   elems.push('<select><option value="1">foo</option></select>')
  }
  $a_items.html(elems.join(""));
  $b_items.html(elems.join(""));
  
  // was test 1, eliminating cause it's pretty fast
  $a_items.find('input');
  $b_items.find('input');
  
  // test 2: see prev note
  $a_items.find('li');
  $b_items.find('li');
  
  // test 3:
  $a_items.find('li').add('.lonely');
  $b_items.find('li').add('.lonely');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
1.4.2 operation
$a_items.find('li').add('#items div');
ready
1.5.2 operation
$b_items.find('li').add('#items div');
ready

Revisions

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

  • Revision 1: published by Charles McNulty on
  • Revision 4: published by Charles McNulty on
  • Revision 5: published by Charles McNulty on
  • Revision 6: published by Volker Mische on
  • Revision 7: published on