473,770 Members | 4,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.NET versus C++ compiled code

Joe
Hi,

I am looking to start a brand new project. Yeahhh! ;-)
The code will do a lot of processor intensive processing. I mean a
lot
of loops to archieve big calculations. You know recursive functions
and everything. Since I am a .NET programmer I have a question. Is
there a real big difference in term of performance (based on the
processors we have in our machine nowadays) between a .NET (C#)
program and the same one written in C++ compiled with Microsoft or
Borland C++ compiler.
I know that is a big question! Probably that too much factors can
influence the overall result.
Thanks.

Aug 27 '07 #1
5 1317
Joe wrote:
[...]
Is
there a real big difference in term of performance (based on the
processors we have in our machine nowadays) between a .NET (C#)
program and the same one written in C++ compiled with Microsoft or
Borland C++ compiler.

I know that is a big question! Probably that too much factors can
influence the overall result.
My experience has been that the overhead is much smaller than I would
have expected before I started doing .NET programming a few years ago.
Under normal conditions, where the code is not entirely CPU-bound, the
overhead is practically invisible, because the code is mostly waiting
for other things anyway.

If you have code that _is_ completely CPU-bound, you may be able to
measure a difference. If that code takes a long time to run, that
difference may translate to a genuinely noticeable delay. But it's
impossible to say in advance what sort of exact difference you might
notice without knowing the specifics of your algorithm.

Also in my experience, it has been true that if something needs speeding
up, usually the first place to start is fixing the algorithm, which is
almost never written optimally to start with. You might speed something
up by 10-25% (depending on a variety of factors) moving code to C++,
whereas fixing the algorithm can often speed things up by 50%, 100%, or
more. Algorithm problems are much more common than platform problems.

There are always exceptions, of course, but those will only be
identified by first making sure you have the most optimal algorithm, and
then doing an actual comparison between the C# and C++ versions of the
algorithm. It's impossible to say in advance what difference, if any,
there might be.

Pete
Aug 27 '07 #2
On 27 ago, 09:24, Joe <jonathanpou... @globetrotter.n etwrote:
Hi,

I am looking to start a brand new project. Yeahhh! ;-)

The code will do a lot of processor intensive processing. I mean a
lot
of loops to archieve big calculations. You know recursive functions
and everything. Since I am a .NET programmer I have a question. Is
there a real big difference in term of performance (based on the
processors we have in our machine nowadays) between a .NET (C#)
program and the same one written in C++ compiled with Microsoft or
Borland C++ compiler.

I know that is a big question! Probably that too much factors can
influence the overall result.

Thanks.
The CLR spent some time compiling the IL to native, but this is only
the first a function is called but the .NET allocation of objects is
more efficient that the traditional C++. As you say there are ver
factors. Anyway you can compile the application for an especial
plataform, an generate a native code instead an IL.
Another issue can be create some functions in c++ and interop later.
Or you can try the C++/CLI language and have both managed an umnanaged
shipping the best of two worlds

The desicion is yours!

regards

Aug 27 '07 #3

"Horacio Nuñez Hernández" <hn******@gmail .comwrote in message
news:11******** *************@k 79g2000hse.goog legroups.com...
On 27 ago, 09:24, Joe <jonathanpou... @globetrotter.n etwrote:
>Hi,

I am looking to start a brand new project. Yeahhh! ;-)

The code will do a lot of processor intensive processing. I mean a
lot
of loops to archieve big calculations. You know recursive functions
and everything. Since I am a .NET programmer I have a question. Is
there a real big difference in term of performance (based on the
processors we have in our machine nowadays) between a .NET (C#)
program and the same one written in C++ compiled with Microsoft or
Borland C++ compiler.

I know that is a big question! Probably that too much factors can
influence the overall result.

Thanks.

The CLR spent some time compiling the IL to native, but this is only
the first a function is called but the .NET allocation of objects is
more efficient that the traditional C++. As you say there are ver
factors. Anyway you can compile the application for an especial
plataform, an generate a native code instead an IL.
Another issue can be create some functions in c++ and interop later.
Or you can try the C++/CLI language and have both managed an umnanaged
shipping the best of two worlds
Please note that the Microsoft C++ compiler (used also for C++/CLI) does a
lot of optimizations not supported by C#.

However, for code heavy on recursive functions, you should definitely
consider a functional language, where the optimizers are written
specifically to deal with recursion.
Aug 27 '07 #4
Joe wrote:
The code will do a lot of processor intensive processing. I mean a
lot
of loops to archieve big calculations. You know recursive functions
and everything. Since I am a .NET programmer I have a question. Is
there a real big difference in term of performance (based on the
processors we have in our machine nowadays) between a .NET (C#)
program and the same one written in C++ compiled with Microsoft or
Borland C++ compiler.
Even for CPU intensive code I would expect the .NET code to
be almost as fast as the native code - within 20% of the
C++ compiler (with maximum optimization - C# will be faster
than default C++ compiler options). But for a few cases it
is possible to code C++ in a way that are much faster than C#
sometimes 2-3 times as fast. Whether you code contain
examples of that is impossible to say upfront.

Arne
Aug 28 '07 #5
Hi,
I once ported my c++ ray tracer to c# and found that the c# code was
approximately 10% slower than c++. Ray tracing is probably once of the most
recursive algorithms and is quite heavy on floating point and math - lots of
sqrt() and such.

Though performance is generally paramount in Ray tracing, the productivity
gain in writing in c# over c++ I am willing to lose that small performance
loss.

Besides, I can always fine tune some aspects and write in c++ interop.

--
Cheers,
Micky D

"Joe" <jo************ @globetrotter.n etwrote in message
news:11******** *************@d 55g2000hsg.goog legroups.com...
Hi,

I am looking to start a brand new project. Yeahhh! ;-)
The code will do a lot of processor intensive processing. I mean a
lot
of loops to archieve big calculations. You know recursive functions
and everything. Since I am a .NET programmer I have a question. Is
there a real big difference in term of performance (based on the
processors we have in our machine nowadays) between a .NET (C#)
program and the same one written in C++ compiled with Microsoft or
Borland C++ compiler.
I know that is a big question! Probably that too much factors can
influence the overall result.
Thanks.
Oct 17 '07 #6

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

Similar topics

6
2225
by: DesignGuy | last post by:
I've read comparison of Perl vs. PHP regarding features and coding, however I would like to know how each affects server load. I am looking at two scripts - one in Perl and the other in PHP - for the Amazon Product Feed. My understand is that Perl must be compiled on each execution and that PHP does not, therefore PHP is less of a load on the server. Comments, anyone?
9
2182
by: MStepansky | last post by:
Whats the difference between Javascript and Java3D? I mean can Javascript do like Java3D can? Or is Java3D on top of Javascript (the core, if thats what it is)? Then I should learn Javascript BEFORE Java3D, right? no? Worse, whats the difference between Java and Javascript? Whats the difference between Visual Basic and Visual Java++? (I still thought Visual Basic is like BASIC programming to allow you to write
10
9588
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the 'case' code snippet does not. (the code's function is illustrative.) ////////////////////////////////////////// //////// working 'if/else' switch //////// //////////////////////////////////////////
2
252
by: G.H.Lawrence | last post by:
Hello. I am relatively new to VS.NET and have ingerited a web application built by 2 previous developers. The most recent one compiled his C# source to a dll, the first one left her C# source as aspx.cs files. I have to debug and enhance the appliation but am running into a couple of issues 1. in order to analyze the C# code, I must decompile the existing dll someho 2. I have a source tree from the last developer but he wasn't a diligent...
25
1946
by: Siv | last post by:
Hi, As part of an evaluation of a small utility that I wrote that converts some data held in a large number of Excel spreadsheets into SQL Server, I decided to convert the utility to VB .NET and run both versions both in the IDE and as standalone compiled exe and see what the difference in time to complete was. The utility has to read 3842 single page Excel Sheets that contain a block of data 12 rows deep and 55 columns across, this...
83
11639
by: sunny | last post by:
Hi All What is C99 Standard is all about. is it portable, i mean i saw -std=C99 option in GCC but there is no such thing in VC++.? which one is better ANSI C / C99? can i know the major difference between C99 & ANSI C standards?
6
3013
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation for one of the Pear modules for creating XML and it didn't look like much. I've used Perl XML:Twig and I have the impression that there is more Perl stuff available as well as the Perl stuff being well documented as I have a Perl DBI book, a Perl...
9
1340
by: Joe | last post by:
Hi, I am looking to start a brand new project. Yeahhh! ;-) The code will do a lot of processor intensive processing. I mean a lot of loops to archieve big calculations. You know recursive functions and everything. Since I am a .NET programmer I have a question. Is there a real big difference in term of performance (based on the processors we have in our machine nowadays) between a .NET (C#) program and the same one written in C++...
1
195
by: stupid48 | last post by:
Ok, I'm just a server guy with a bit a VS 2005 experience. I know that you can deploy asp.net apps either compiled or not compiled. My developer says that he prefers not to compile. I have to ask about the pro's and con's of both. I'm especially concerned about performance of each and the security pros and cons of each. Does anyone have a theory on this and\or a link to a site that I can read? Thanks very much and sorry if this...
0
9602
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.