Created
May 19, 2014 12:10
-
-
Save breyed/dfbf2af2e4667fd29acd to your computer and use it in GitHub Desktop.
Why is checked arithmetic in .NET sometimes faster than unckecked?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code for http://stackoverflow.com/q/23736786/145173 | |
using System; | |
using System.Diagnostics; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var s = new Stopwatch(); | |
s.Start(); | |
int a = 0; | |
for (int i = 0; i < 100000000; i += 3) { | |
if (i == 1000) | |
i *= 2; | |
if (i % 35 == 0) | |
++a; | |
} | |
s.Stop(); | |
Console.WriteLine(s.ElapsedMilliseconds); | |
Console.WriteLine(a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment