How can I improve C # code to prove that C # can be as fast as C ++ for my colleague?
You can not. There are legitimate areas where C ++ is significantly faster than C #. But there are also areas where C # code will work better than equivalent C ++ code. These are different languages ββwith different strengths and weaknesses.
But as a programmer, you really have to base your decisions in logic.
Logic dictates that you must first gather information and then decide based on this.
You, on the contrary, made a decision first, and then searched for information to support it. This may work if you are a politician, but this is not a good way to write software.
Don't go hunting for evidence that C # is faster than C ++. Instead, check which option is faster in your case.
In any case, if you want to prove that X can be as fast as Y, you should do it in the usual way: make X as fast as Y. And as always, when performing performance tuning, the profiler is your best friend. Find out exactly where the extra time is spent, and then find out how to fix it.
Memory usage is a lost reason..NET just uses more memory for several reasons:
- it has a large runtime library that must be present in the process address space
- .NET objects have additional members not present in C ++ classes, so they use more memory
- The garbage collector means that, as a rule, you will have a certain amount of "no longer used, but not recovered" memory lying around. In C ++, memory is usually freed immediately. In .NET, this is not so ..NET is based on the assumption that memory is cheap (which is usually true).
source share