473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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!
Nov 15 '05 #1
10 2331
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.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Henrik Andersen" <pe*********@hotmail.com> wrote in message
news:Oe*************@tk2msftngp13.phx.gbl...
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!

Nov 15 '05 #2
On Wed, 17 Sep 2003 19:12:27 +0200, "Henrik Andersen"
<pe*********@hotmail.com> wrote:
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

--
NULL

Nov 15 '05 #3
> 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).
Nov 15 '05 #4
Found something...

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

More differences?

"Henrik Andersen" <pe*********@hotmail.com> skrev i en meddelelse
news:Oe*************@tk2msftngp13.phx.gbl...
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!

Nov 15 '05 #5
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" <pe*********@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Found something...

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

More differences?

Nov 15 '05 #6

"Henrik Andersen" <pe*********@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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? More differences?

"Henrik Andersen" <pe*********@hotmail.com> skrev i en meddelelse
news:Oe*************@tk2msftngp13.phx.gbl...
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!


Nov 15 '05 #7
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.

"Henrik Andersen" <pe*********@hotmail.com> wrote in message news:Oe*************@tk2msftngp13.phx.gbl...
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!

Nov 15 '05 #8
timtos <ti****@gmx.de> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #9
> 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
Nov 15 '05 #10
Gawelek <ga*****@NOSPAMEKpoczta.gazeta.pl> wrote:
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.


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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Alper AKCAYOZ | last post by:
Hello Esteemed Developers and Experts, I have been using Microsoft Visual C++ .NET for 1 year. During this time, I have searhed some topics over internets. Most of the topics about .NET is...
6
by: Omid Hodjati | last post by:
Hi All, I implemented an encryption algorithm using C#, native C++ and managed C++. Then I measured the CPU time used for executing this algorithm in all implementation. The managed version of...
6
by: Chris Wood | last post by:
I have a complex codebase developed in Managed C++ that I am not particularly looking forward to porting to C++/CLI :) I'd like to know what the most compelling arguments for doing so are so I can...
2
by: The unProfessional | last post by:
In my current project (my first project using vc w/ managed extensions), I'm directly #using <mscorlib.dll>, so it's necessary for me to use the __nogc and __gc constructs when defining classes or...
7
by: Z-Mechanic | last post by:
Hello everybody! I have a question. Anybody knows why managed function calls faster in MC++ rather than unmanaged function (defined with #pragma umanaged)? The differences is about 4 times...
3
by: JoeProgrammer | last post by:
A couple of questions re. managed vs. unmanaged code. 1. I know this depends on the app, but how much faster is unmanaged code vs. managed code? Is there an average figure for this? 2. Is it as...
0
by: Ewart MacLucas | last post by:
generated some WMI managed classes using the downloadable extensions for vs2003 from mircrosoft downloads; wrote some test code to enumerate the physicall processors and it works a treat, but a...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
66
by: John | last post by:
Hi What are the advantages actually achieved of managed code? I am not talking of theory but in reality. Thanks Regards
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.