C# Compiler Optimizations

前端 未结 3 775
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 09:03

I\'m wondering if someone can explain to me what exactly the compiler might be doing for me to observe such extreme differences in performance for a simple method.



        
3条回答
  •  别那么骄傲
    2020-12-29 09:19

    I don't know what optimizations it is doing but I can show you how you can find out for your self.

    First build your code optimized and start it without the debugger attached (the JIT compiler will generate different code if the debugger is attached). Run your code so that you know that section was entered at least once so the JIT Compiler had a chance to process it and in Visual Studio go to Debug->Attach To Process.... From the new menu choose your running application.

    Put a breakpoint in the spot you are wondering about and let the program stop, once stopped go to Debug->Windows->Dissasembly. That will show you the compiled code the JIT created and you will be able to inspect what it is doing.

    (Click for larger view)

提交回复
热议问题