Answer the question
In order to leave comments, you need to log in
Is it true that programs written in C++ run faster than those written in C#. for example?
And what is the reason for this superiority, if it exists?
Answer the question
In order to leave comments, you need to log in
generally true. Due to the absence of a virtual machine (in the case of c#, this is the CLR). But such moments can turn out to be pluses (some things related to caching dynamic functions, for example).
Programs written in C# are compiled into bytecode , which is then executed by a virtual machine . Roughly speaking, a processor emulator. In addition, C# programs use automatic memory management, so their execution is periodically suspended for garbage collection .
In 2018, C++ is 2-3 times faster than C#. But here you still need to take into account the curvature of the programmer's hands and algorithms. So there is no difference. Of course, you can, as an addition to your computer science fundamentals, look into this issue or google it.
https://days2011.scala-lang.org/sites/days2011/fil...
In the same Amazon on some services 90% Scala and 10% C++.
Causes of brakes - GC (every {} is called), VM and all sorts of "Boxing and Unboxing". Also, memory. A VM can work with memory pools and allocate hundreds of megabytes at once. But it all fizzles out. Look at the Amazon disable GC in Java VM.
void func1(string s) // will run faster in Java than in C++
in addition to all of the above, the C # code (more precisely, the dotnet runtime) accesses the system through intermediary libraries,
but in the end, it all depends on the task. purely computational algorithms can approach comparable execution times. especially when using Ngen , and with the active use of system resources, the gap can grow quite significantly
and also depends on the programming style. the same C ++ is gradually acquiring the possibilities of functional programming (although C # is faster). this paradigm can reduce development time and improve code reliability, but usually at the cost of performance
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question