eval() vs new Function()

JavaScript performance comparison

Revision 9 of this test case created by Timothy Gu

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var str = '(function(a, b, c, d, e, f, g) {return a * b * c * d * e * f * g;})';
  
  var evaledFunc = eval(str);
  var funcedFunc = new Function('', 'return ' + str)();

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
eval()
evaledFunc(100.1, 200.2, 300.3, 400.4, 500.5, 600.6, 700.7);
pending…
new Function()
funcedFunc(100.1, 200.2, 300.3, 400.4, 500.5, 600.6, 700.7);
pending…

Compare results of other browsers

Revisions

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

0 Comments