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.
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)