473,324 Members | 2,548 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,324 software developers and data experts.

.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 1302
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.netwrote:
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*********************@k79g2000hse.googlegro ups.com...
On 27 ago, 09:24, Joe <jonathanpou...@globetrotter.netwrote:
>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.netwrote in message
news:11*********************@d55g2000hsg.googlegro ups.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
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...
9
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...
10
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 ...
2
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...
25
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...
83
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...
6
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...
9
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.