Named vs eval

Benchmark created by James Hartig on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

var data = [], d = 0;
    while (d++ < 100) { data.push(d); }
    function test(rows) {
        var squares = [];
        for (var i = 0; i < 100; i++) {
            squares.push(Math.exp(rows[i], 2));
        }
        return squares;
    }
    
    var code = 'return [\n';
    for (var n = 0; n < data.length; n++) {
        code += 'Math.exp(rows[' + n + '], 2),';
    }
    code = code.substring(0, code.length - 1) + '];\n';
    var evalTest = new Function('rows', code);

Test runner

Ready to run.

Testing in
TestOps/sec
Named Function
test(data);
ready
Eval
evalTest(data);
ready

Revisions

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

  • Revision 1: published by James Hartig on