Search code examples
.netjitngen

Measuring JIT time of a .NET application


I'm aware that you can use NGen to make native pre-compiled images of your .NET application.

But how do you measure how much time your application has spent in JIT? I'd like to know how much time is to be saved before doing this.


Solution

  • Since NET6.0 you can use the System.Runtime.JitInfo static class to get an overview:

    https://learn.microsoft.com/en-us/dotnet/api/system.runtime.jitinfo?view=net-6.0

    Example:

    Console.WriteLine($"Time: {JitInfo.GetCompilationTime(false)}");
    Console.WriteLine($"ILBytes: {JitInfo.GetCompiledILBytes(false)}");
    Console.WriteLine($"MethodCount: {JitInfo.GetCompiledMethodCount(false)}");
    

    Passing in true to these methods returns values for the current thread (instead of global).