I notice the bottleneck is here
I think Javascript.NET has similar optimization because the first code below runs almost 8~10x slower than the second one
var uniqueName = documentNameManager.GetUniqueName(documentName, "Script Document");
It is generating a new name even the same script is being executed twice. If I changed it to uniqueName = code.GetHashCode().ToString() // Just an example to create a unique code based on the script
If the same script is being executed twice, it will run extremely fast and efficient (Should have the same performance as compiling the script). I think Javascript.NET has similar optimization because the first code below runs almost 8~10x slower than the second one
for (int i = 0; i < 10000; i++)
{
engine.Run("Math.random() + " + i);
}
for (int i = 0; i < 10000; i++)
{
engine.Run("Math.random()");
}