I was thinking about the difference in speed from C ++ to C #, mainly about compiling C # into byte code, which is accepted by the JIT compiler (is that right?) And all C # checks.
I notice that you can disable many of these functions, both in the compilation options and possibly with the unsafe keyword, since unsafe code cannot be verified using the common language runtime.
Therefore, if you wrote a simple console application in both languages, which deployed an imaginary coin infinitely many times and displayed the results on the screen every 10,000 and so on, how much would there be a difference in speed? I chose this because it is a very simple program.
I would like to check this out, but I don't know C ++ or I have tools to compile it. This is my version of C #, though:
static void Main(string[] args) { unsafe { Random rnd = new Random(); int heads = 0, tails = 0; while (true) { if (rnd.NextDouble() > 0.5) heads++; else tails++; if ((heads + tails) % 1000000 == 0) Console.WriteLine("Heads: {0} Tails: {1}", heads, tails); } } }
Is the difference sufficient to intentionally compile sections of code "unsafe" or into DLLs that do not have some compilation options, such as overflow checking? Or does this happen in a different way, where it would be useful to compile partitions in C ++? I am sure that the speed of interaction also comes into play.
To avoid subjectivity, I repeat the specific parts of this question:
- Does C # have performance improvements when using unsafe code?
- Do compilation options such as disabling overflow checking, performance improvements, and do they affect insecure code?
- Will the program above be higher in C ++ or casually different?
- Is it worth compiling long intensive crunching tasks in a language such as C ++, or is it used / unsafe for a bonus? Less subjective, can I perform an intensive operation faster by doing this?
source share