IIFE vs. simple function

JavaScript performance comparison

Test case created by Chris Khoo


By "simple", I mean simple to understand.

If you know of a better term, please let me know!

Preparation code

Benchmark.prototype.setup = function() {
    var iife = (function() {
      function helper(arg) {
        return arg + 1;
      return function(arg1, arg2) {
        return helper(arg1) + helper(arg2);
    function simple(arg1, arg2) {
      function helper(arg) {
        return arg + 1;
      return helper(arg1) + helper(arg2);

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
iife(1, 2);
simple(1, 2);

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

Compare results of other browsers

1 comment

Chris Khoo (revision owner) commented :

BTW, the reason IIFE is faster is because it doesn't need to re-declare the "helper" function every time it runs.

Comment form temporarily disabled.

Add a comment