Question should be “Why do I see such a difference on my machine?”. I cannot reproduce such a huge speed difference and suspect there is something specific to your environment. Very difficult to tell what it can be though. Can be some (compiler) options you have set some time ago and forgot about them.
I have create a console application, rebuild in Release mode (x86) and run outside VS. Results are virtually identical, 1.77 seconds for both methods. Here is the exact code:
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
int count = 0;
for (uint i = 0; i < 1000000000; ++i)
{
// 1st method
var isMultipleOf16 = i % 16 == 0;
count += isMultipleOf16 ? 1 : 0;
// 2nd method
//count += i % 16 == 0 ? 1 : 0;
}
sw.Stop();
Console.WriteLine(string.Format("Ellapsed {0}, count {1}", sw.Elapsed, count));
Console.ReadKey();
}
Please, anyone who has 5 minutes copy the code, rebuild, run outside VS and post results in comments to this answer. I’d like to avoid saying “it works on my machine”.
EDIT
To be sure I have created a 64 bit Winforms application and the results are similar as in the the question – the first method is slower (1.57 sec) than the second one (1.05 sec). The difference I observe is 33% – still a lot. Seems there is a bug in .NET4 64 bit JIT compiler.