eval() vs new Function()

JavaScript performance comparison

Test case created by tbruce

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function useEval() {
    var func = eval('(function(a, b, c, d, e, f, g) {return a * b * c * d * e * f * g;})');
    var result = func(100.1, 200.2, 300.3, 400.4, 500.5, 600.6, 700.7);
    }
   
    function useNewFunction() {
    var func = new Function(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 'return a * b * c * d * e * f * g;');
    var result = func(100.1, 200.2, 300.3, 400.4, 500.5, 600.6, 700.7);
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
eval()
useEval();
pending…
new Function()
useNewFunction();
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. Here’s a list of current revisions for this page:

0 comments

Add a comment