Dynamic Func Eval vs New Function

Benchmark created by Tom on


Description

I'm creating a simple function that is going to be run as a kernel to generate an array of samples from multiple input arrays.

So for example out[x] = in1[x] + in2[x] repeated from [0..n]

Because these combinations can be fairly complex, I wanted a dynamic way of building the kernel. In the process I've discovered that while IE and Firefox seem to JIT compile this kernel, chrome does not.

Why?

Setup

eval("function eval_add(in_1, in_2){return (in_1 + in_2);};")
    
    func_add = new Function("in_1", "in_2", "return (in_1 + in_2);")
    
    function real_add(in_1, in_2){return (in_1 + in_2);};

Test runner

Ready to run.

Testing in
TestOps/sec
Eval Add
test_out = []
for (i = 0; i< 100; ++i){
  test_out.push(eval_add(i, i+1));
}
ready
Func Add
test_out = []
for (i = 0; i< 100; ++i){
  test_out.push(func_add(i, i+1));
}
ready
Real Add
test_out = []
for (i = 0; i< 100; ++i){
  test_out.push(real_add(i, i+1));
}
ready

Revisions

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