Is there a way in Jint to store a function to a Func?

173 views Asked by At

I am using Jint to dynamically run functions for my C# code. It works perfectly for running the functions. However the execution time is linear per execution

var engine = new Jint.Engine();
var rule = File.ReadAllText("file.js");
for (int i = 0; i < 1000000; i++)
{
  engine.Execute(rule);
}

I am going to be running the functions potentially upwards of 1million times. Currently this code takes 126197ms (2minutes 6s) to run! Is there a way to store the function in C# after it's been read by the engine? Or is there another library that would handle this number of executions in a faster timeframe?

EDIT

I'm thinking of something like this:

var engine = new Engine().Execute("function() { /* code here */}");
var method = (Func<TypeOne, TypeOne, ResultType>)engine..

var result = method(paramOne, paramTwo);

Thanks,

0

There are 0 answers