jQuery.live vs jQuery.delegate (v35)

Revision 35 of this benchmark created by PW on


Description

comparison of jQuery methods live and delegate over 1000 items.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<ul id="myList">
</ul>

<script>
  var listArray = [],
      tpl = '<li><input type="checkbox" name="check_%i" value="%i" /></li>',
      tplFn = function(value) {
    return tpl.replace(/%i/g, value);
      },
      i;
  
  // loop and create 1000 entries
  for (i = 0; i <= 1000; i++) {
   listArray.push(tplFn (i));
  }
  
  
  $('#myList').append(listArray.join(''));
var myList = $('#myList');
var $body = $(document.body);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
on
myList.on('click', 'input:checkbox', $.noop);
ready
on (body)
$body.on('click', 'input:checkbox', $.noop);
ready
delegate
myList.delegate('input:checkbox', 'click', $.noop);
ready
delegate to document.body
$body.delegate('input:checkbox', 'click', $.noop);
ready

Revisions

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