This project has moved and is read-only. For the latest updates, please go here.

is there a way to cache compilation ?

Oct 12, 2011 at 8:59 PM

I need to run an script a lot of times, and waht to speed jurassic caching the compilation of an script

example:

int ExecuteScript (int a)
{

var engine = new Jurassic.ScriptEngine();
 
var cached_compilation = engine.GetFromCache ("scriptcachename");
 
if (cached_compilation == null)
{
engine.AddToChache ("scriptcachename", "1.5 + 2.4 + z"); // Here we are compiling the script
  // Also can be an engine.RemoveFromCache ("scriptcachename")
}

engine.SetGlobalValue("z", a);
 
return engine.Evaluate <int> (cached_compilation);  // Here we are execute the script but not compiling it to CIL

Oct 13, 2011 at 2:01 AM
Edited Oct 13, 2011 at 2:09 AM

No need to create something new; you can do this already :-)

scriptEngine.Execute("function MyFunc(z) { return 1.5 + 2.4 + z; }");
var myFunc = (Jurassic.Library.FunctionInstance)scriptEngine.GetGlobalValue("MyFunc");
for (int i = 0; i < 1000; i ++)
{
    Console.WriteLine(myFunc.Call(null, i));
}