jQuery chaining (v11)

Revision 11 of this benchmark created on


Description

Tests whether chaining jQuery function calls is noticeably faster than separate calls.

Preparation HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script>
<div id="theDiv">
  Some text
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
Chained
$('#theDiv').addClass('test').removeClass('test');
ready
Separate calls
$('#theDiv').addClass('test');
$('#theDiv').removeClass('test');
ready
Separate calls (cached)
var d = $('#theDiv');
d.addClass('test');
d.removeClass('test');
ready
Chained (cached)
var theDiv = $('#theDiv');
theDiv.addClass('test').removeClass('test');
ready
Chained - Hybrid
$(document.getElementById('theDiv')).addClass('test').removeClass('test');
ready
Separate calls - Hybrid
var theDiv = $(document.getElementById('theDiv'));
theDiv.addClass('test');
theDiv.removeClass('test');
ready

Revisions

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