Open alex-hedley opened 1 year ago
Speeding up CSharpCompilation.Emit? https://stackoverflow.com/questions/62625367/speeding-up-csharpcompilation-emit
private static T Measure<T>(string caption, Func<T> generator)
{
var now = DateTime.Now;
var result = generator();
var end = DateTime.Now - now;
Debug.WriteLine($"{caption}: {end.TotalMilliseconds} ms");
return result;
}
var compilation = Measure("Compile", () => CSharpCompilation.Create(
"Bar.dll",
new[] {syntaxTree},
typeRefs.Select(x => MetadataReference.CreateFromFile(x)),
new CSharpCompilationOptions(
OutputKind.DynamicallyLinkedLibrary,
optimizationLevel: OptimizationLevel.Debug
)
));
Compile: 43,4261 ms
Possibly use example:
https://www.csharpstar.com/measure-memory-usage-of-your-application-csharp/
Stats