jQuery .live() vs .delegate() vs .on()

JavaScript performance comparison

Revision 55 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js">
</script>
<div id="context">
  <p>
    Some paragraph
  </p>
</div>
<script>
Benchmark.prototype.setup = function() {
    var el = document.getElementsByTagName('p')[0];
};

Benchmark.prototype.teardown = function() {
    $('p').die('click');
    $('#context').undelegate('p', 'click', $.noop);
    $(document).undelegate('p', 'click', $.noop);
    $('#context').off('click', 'p', $.noop);
    $(document).off('click', 'p', $.noop);
    $("p").off("click", $.noop);
    $("p").unbind('click');
};
</script>

Preparation code output

Some paragraph

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
.live()
$('p').live('click', $.noop);
pending…
.live() with context
$('p', $('#context')).live('click', $.noop);
pending…
.delegate()
$('#context').delegate('p', 'click', $.noop);
pending…
.delegate() on document
$(document).delegate('p', 'click', $.noop);
pending…
.on()
$('#context').on('click', 'p', $.noop);
pending…
.on() on document
$(document).on('click', 'p', $.noop);
pending…
.on() direct
$("p").on("click", $.noop);
pending…
.click()
$("p").click($.noop);
pending…
.bind()
$("p").bind('click', $.noop);
pending…
native click
el.addEventListener('click', function() {
  $.noop
});
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. Here’s a list of current revisions for this page:

0 comments

Add a comment