Cost of creating inner function

Benchmark created by T.J. Crowder on


Description

Looks at the cost of creating an inner function

Setup

function fooWithBar(a, b) {
        function bar(x) {
            return x * b;
        }
    
        if (a < 3) {
            return bar(a * 2);
        }
        return bar(a * 3);
    }
    
    function fooWithoutBar(a, b) {
        if (a < 3) {
            return (a * 2) * b;
        }
        return bar(a * 3) * b;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
With a function
if (fooWithBar(2, 3) !== 12) throw "Error in test";
ready
Without function
if (fooWithoutBar(2, 3) !== 12) throw "Error in test";
ready

Revisions

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

  • Revision 1: published by T.J. Crowder on
  • Revision 3: published by T.J. Crowder on