Eval vs new Function vs function()

JavaScript performance comparison

Revision 6 of this test case created by PAEz

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var _={a:1,b:2};
    var func= new Function("$","return $.a+$.b");
    var funcAdd = function (){
    var result=arguments[0];
    for (var i=1,end=arguments.length;i<end;i++){
    result+=arguments[i];
    }
    return result;
    }
};
</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
var b=eval('_.a+_.b');
pending…
new Function
var b=func(_);
pending…
function
var b=funcAdd(_.a,_.b);
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