How to improve performance when executing the cSharpScript's RunAsync method. #60834
Unanswered
amoldorkar-ezest
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a requirement where I have to run the script in the loop for the calculations. The first time when the script executes it takes 2 to 3 seconds approx. afterward, it takes around 30 to 40 milliseconds. following is the sample code.
List<string> formulas = new List<string>(); //List<string> formulas holds 10,000 to 50,000 items
foreach(var formula in formulas)
{
Script<double?> script = CSharpScript.Create<double?>(formula, ScriptOptions.Default .WithOptimizationLevel(Microsoft.CodeAnalysis.OptimizationLevel.Release)).WithOptions(ScriptOptions.Default.AddImports(new string[] { "System" }));
var value = (await script.RunAsync()).ReturnValue;
//perform business logic with the variable value
}
If we take average time as 35ms for 50,000 records it would take around half an hour which in my case too much also the number of records in the formulas list will increase in the future.
Is there any solution for this?
Many thanks.
Beta Was this translation helpful? Give feedback.
All reactions