Apologies for the unhelpful title, I'm not sure I actually understand that what I'm asking is happening. I know embarrassingly little about what the CLR and JIT does or how to check that it's doing what I think it should be doing.
Let's say I have the following method:
void DoSomething(bool log) {
for (int i=0; i< 1000000; i++) {
if (log) {
Console.WriteLine(i);
}
Console.WriteLine(i*2);
}
}
Now, if my method call is DoSomething(false)
, will the CLR/JIT know to not check if (log)
100,000 times? Basically, will it automatically convert it to:
void DoSomething_noLog() {
for (int i=0; i< 1000000; i++) {
Console.WriteLine(i*2);
}
}
If it does know to do this automatically, how can I verify that it really is doing this?