I created two methods, one of which completed checked
, and the other unchecked
. When searching in IL, only one difference is the mul
operation (which performs the multiplication operation), for the marked mul.ovf
generated for unchecked - mul
.
To summarize, I believe that the difference in one CPU operation does not affect performance, the only difference would be in the case of overflow using checked
- in this case an OverflowException would be thrown, which would obviously slow down the execution.
MSDN:
The following Microsoft Intermediate Language (MSIL) statements throw overceptionException:
[Test] public void Checked() { checked { int i = int.MaxValue; i = i * 100; Debug.WriteLine(i); } } [Test] public void UnChecked() { unchecked { int i = int.MaxValue; i = i * 100; Debug.WriteLine(i); } }
And then using ILDASM, see IL:
CHECKED ():
UNCHECKED ():
source share