Dynamic name of functions

Benchmark created by Enzo on


Setup

var funname = 'funname';
  
  function newfun0() {
      return function funname(a,b){ return a*b; };
  }
  
  function newfun1() {
      eval("var fun = function "+funname+"(a,b){ return a*b; }");
      return fun;
  }
  
  function newfun2() {
      return new Function(
          "return function " + funname + "(a,b){ return a*b; }"
      )();
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Normal
var f = newfun0();
f(2,3);
ready
eval
var f = newfun1();
f(2,3);
ready
new Function
var f = newfun2();
f(2,3);
ready

Revisions

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

  • Revision 1: published by Enzo on