Cost of creating inner function (v3)

Revision 3 of this benchmark created by T.J. Crowder on


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 (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