Is C++ managed code compiler faster than C#?

  • Thread starter Thread starter Henrik Andersen
  • Start date Start date
H

Henrik Andersen

Hi newsgroup

Does the c++ compiler generate faster code at execution time than the C#
compiler?

Does the c++ compiler have more optimisations than the C# compiler?

Thanks in advance!
 
Henrik,

I don't know that you will get better code optimization using Managed
Extensions in C++ versus C# or VB. While each compiler will produce
different IL, I don't believe that any one compiler will produce something
so different as to affect performance (then again, all those nop
instructions that the VB compiler spits out can be a problem).

Hope this helps.
 
Hi newsgroup

Does the c++ compiler generate faster code at execution time than the C#
compiler?

Does the c++ compiler have more optimisations than the C# compiler?

Well, you have to consider that C# was designed specifically for the
..net framework, thus allowing the C# compiler to be designed to spit
out 'better' (note the ') MSIL.
Both the compilers for managed C++ en VB.net have legacy issues that
might (might, not will) lead to lesser-quality MSIL
 
Well, you have to consider that C# was designed specifically for the
.net framework, thus allowing the C# compiler to be designed to spit
out 'better' (note the ') MSIL.
Both the compilers for managed C++ en VB.net have legacy issues that
might (might, not will) lead to lesser-quality MSIL

The fact that C# was designed specifically for the framework means nothing.
You could write a COBOL compiler for .NET (using the System.Reflection.Emit
namespace) that's even more efficient than the C# compiler (from looking at
the optimized IL produced by the C# compiler, just about the only thing that
can be improved is it's usage of the stack).
 
Found something...

C++ have whole program optimization, which C# does not have

More differences?
 
For best comparison, I suggest you write a very simple program in C++, and
an equivelant program in C#, and see what the difference is between the
disassembed code. If you would like to test a more complex feature of the
framework, that can be done in the same way.

I'm not sure what you mean by "whole program optimization", but if the
correct switch is provided (/o), the C# compiler will optimize everything.

IMO, C/C++ is much better suited for low level programming, or in cases
where speed is fundamentally essential (i.e. DX and OpenGL games), and in
these cases you probably wouldn't be coding to a virtual machine. In the
framework, the cons of using C++ far outweigh the pros. Most notably, the
development time is longer, with the 'advantage' of little to no improvement
in speed.

Chris LaJoie
 
Henrik Andersen said:
Found something...

C++ have whole program optimization, which C# does not have
Actually, whole program optimization is irrelevent in the managed world,
whole program optimization cannot be used with the /clr switch.
However, it may matter in non-.NET applications. In what specific scenarios
are you interested in?
 
A difference between VB, C# and C++:

Adding two numbers the output will be:

VB: IL_xxxx: add.ovf
C++: IL_xxxx: add
C# IL_xxxx: add OR add.ovf (depends on compiler setting)

[ovf = overflow checking]

So add is faster but add.ovf is safer...
Greetings,
timtos.
 
timtos said:
A difference between VB, C# and C++:

Adding two numbers the output will be:

VB: IL_xxxx: add.ovf
C++: IL_xxxx: add
C# IL_xxxx: add OR add.ovf (depends on compiler setting)

[ovf = overflow checking]

So add is faster but add.ovf is safer...

"Safer" depends on what you want to happen on overflow. Various
routines (including checksumming) rather depend on the way overflow is
calculated. For instance, a very simple (and not terribly good - only
used for demonstration purposes) checksum routine might be:

short checksum = 0;

foreach (byte b in dataToSum)
checksum += byte;

The resulting 16-bit checksum could easily overflow, but that's okay so
long as everyone treats it the same.
 
Does the c++ compiler generate faster code at execution time than the C#
compiler?

Does the c++ compiler have more optimisations than the C# compiler?

Month ago I carried out some testes, and MC++ was not far behind C++.
And C# was 4x slower then C++, but faster then Java.
My tests were not professional, I am sure, but they show something.

Gawel
 
Gawelek said:
Month ago I carried out some testes, and MC++ was not far behind C++.
And C# was 4x slower then C++, but faster then Java.
My tests were not professional, I am sure, but they show something.

It will be entirely dependent on what you're doing - and how you
measure it. (For instance, in Java you need to let the JIT "warm up"
and find hot spots; in C# you need to at least run the code once so it
will have been JITted; for both you should only measure the time taken
to execute the code rather than the total time for the program, etc.)
You should also be aware that some benchmarks will be optimised away
entirely by the compiler - there was a recent benchmark where someone
was saying how much faster C++ was than .NET (or Java, I can't remember
which) for trigonometric functions: it turned out that because he
wasn't using the results of the trig functions, the C++ compiler wasn't
even calculating them. Once the benchmark was corrected, the speeds
were fairly comparable.

Ultimately, it's only the performance of the real-world app you're
interested in which is relevant. If my app runs find under .NET, that
doesn't necessarily mean that yours will - or vice versa.
 
Back
Top