I reading a book( CLR via c#)in the book writer speak about IL and managed module that managed module compiling in native cpu code and then execute in the book writer said that Managed module Is faster than Unmanaged module.my question is why Managed module Is faster than Unmanaged module but for in Managed module first compile to IL and then compile in native cpu.
(What I wrote below is not mine, it is copy-pasted from a book: CLR via C#, Page No 14
)
When the JIT compiler compiles the IL code into native machine code at run time, the compiler knows more about the execution environment than an unmanaged compiler would know.
Some ways in which managed code can outperform unmanaged code
A JIT compiler can determine when a certain test always fail on the machine that it is running on. Consider the example
if (num_of_cpu > 1)
{
}
This code causes the JIT to not generate any CPU instruction if the machine has only One CPU.