I was comparing the execution times between eval(code) and new Function(code).
And I discovered that new Function(code) is faster than directly execute the same code.
What is the reason?
var start = new Date().getTime();
var test = ''; for (var i = 0; i < 1000000; ++i) { test += 'a'; }
var end = new Date().getTime();
console.log('Execution time: ' + (end - start));
// vs.
var start2 = new Date().getTime();
var f = new Function("var test = ''; for (var i = 0; i < 1000000; ++i) { test += 'a'; }");
f();
var end2 = new Date().getTime();
console.log('Execution time: ' + (end2 - start2));