IIFE vs Standard JS and jQuery (v2)

Revision 2 of this benchmark created by Maciej Żok on


Description

Results are comparable, but IIFE provides local scoping and better minification optimization (more info).

Preparation HTML

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

Setup

$(function() {
      $('body').append('<div id="iffe-test"></div>');
    });

Teardown


    $('div#iffe-test').remove();
  

Test runner

Ready to run.

Testing in
TestOps/sec
Standard JS
var f = function() {
  $('div#iffe-test').append('<p>Test</p>');
};

f();
ready
IIFE
(function($) {
  $('div#iffe-test').append('<p>Test</p>');
})(window.jQuery);
ready
Standard jQuery (DOM fully loaded)
$(function() {
  $('div#iffe-test').append('<p>Test</p>');
});
ready
IIFE (DOM fully loaded)
(function($) {
  $(function() {
    $('div#iffe-test').append('<p>Test</p>');
  });
})(window.jQuery);
ready

Revisions

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