Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: V8ScriptEngine.Compile vs. V8ScriptEngine.Script

0
0
Actually, on second thought, roughly speaking they should be equally fast, as both amount to re-execution of compiled code. The second technique does redeclare the function; that is, it reassigns a global script property. But it probably doesn't duplicate the function, so the redeclaration is effectively a no-op.

However, note that the first technique correctly passes an argument, whereas the second one doesn't, due to the bug described above. Exporting a .NET object to the script engine is not cost-free. Also, the first technique redundantly imports the function from the script engine, and that also is not cost-free. Together these factors might add up to the discrepancy you're seeing. Would it be possible to make the recommended changes (cache the script function in the first case, and fix the argument passing in the second) and rerun the timing tests?

We'd like to reiterate that in both cases you're compiling code once and re-executing it many times. The two techniques have minor differences, but both should be much faster than recompiling the code many times.

Viewing all articles
Browse latest Browse all 2297