473,698 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Improving performance C++/C#

Because of historical reasons, I have both C# and C++ managed/unmanaged code
mixed together in my class library.
But I prefer to port code to C# since it compiles faster and the syntax is
much more readable so I can do more in less time.

The big question now, will I gain/lose performance, given the fact that I
create pure managed code, if I port the managed C++ classes to C# classes? I
cannot port all the classes at once, too much to port, not enough time.

I use the C++ and C# standard edition 2003. For C++ no speed optimizing is
possible, but since C# uses the C# compiler from the .NET framework, I might
have faster speed this way?
Nov 17 '05
29 1790
Ioannis Vranos wrote:
Carl Daniel [VC++ MVP] wrote:
To an extent, this is already happening with .NET.

What mechanism does C# provide for inclusion of source code files?


None. I don't think I implied that it did include any.

Rather, C# provides a module concept that works. That concept can only be
simulated through header conventions in native C++.

-cd
Nov 17 '05 #21
Dan
Olaf Baeyens wrote:
The C# compiler is quite speedy and easy to use on smallish projects,
but
when the project gets large (100's to 1000's of source files), the lack


of
a
real incremental build tips heaviliy in favor of C++ (except for
Rebuild-All, of course).


My own experience is that, with a decent machine (not super, just fairly
decent), we can recompile one of our project's code bases from scratch
(consisting of about 50.000 lines of code and about 250 source files that
compile into about 25 dlls) in less than a minute with the C# compiler.


The
larger code base (around 250.000 lines of code) used to be compilable from
scratch in a couple of minutes or so...

It's not bad, really. However, the project model, overall, usually causes


a
fairly big recompile when you change one of the bottom dependencies, which
can slow the process down.


The same is true in C++. Change one constant, or accidentily type a space in
one of the base headers and I am off agin for another 17 minute recompile.
I have a code base of about 180.000 lines now.

If the C++ people could find a way to avoid this "#include system" and use
the C# like technology then it would help a lot from developer viewpoint in
speeding up development.


In Whidbey it's done with using namespace keywords. e.g. using namespace
System::Windows ::Forms;
Nov 17 '05 #22
Carl Daniel [VC++ MVP] wrote:
What mechanism does C# provide for inclusion of source code files?

None. I don't think I implied that it did include any.

Rather, C# provides a module concept that works. That concept can only be
simulated through header conventions in native C++.

When you are talking about module concept, do you mean the dlls?

--
Ioannis Vranos
Nov 17 '05 #23
Ioannis Vranos wrote:
When you are talking about module concept, do you mean the dlls?


I mean a system with rich meta-data that allows a "client" to be compiled
without needing the source code of the "server". That's the big weakness in
traditional C/C++ - there is no "module" concept that defines a body of
functionality with a clearly defined interface. Instead all we have is a
text-pasting system that can simulate real modules through convention.

In systems that have a cleanly defined module concept (e.g. Borland's
Delphi), changes to the implementation of a module rarely (or
never)necessita te re-compilation of clients of the module. In C and C++,
since all we have to track dependencies is file modification time, there's
simply no way for the compiler to know if a change requires recompilation of
clients or not, so it must take the conservative route and assume that all
changes (to a shared file) are important to clients.

The fact that C++ puts the implementation of the class, even if it's
private, into the field of view of clients further aggravates the situation.
In that regard, I'm not sure that .NET has done enough to shield clients
from internals changes to classes they consume, but it's a big step in the
right direction.

-cd
Nov 17 '05 #24
Carl Daniel [VC++ MVP] wrote:
I mean a system with rich meta-data that allows a "client" to be compiled
without needing the source code of the "server". That's the big weakness in
traditional C/C++ - there is no "module" concept that defines a body of
functionality with a clearly defined interface. Instead all we have is a
text-pasting system that can simulate real modules through convention.

In systems that have a cleanly defined module concept (e.g. Borland's
Delphi), changes to the implementation of a module rarely (or
never)necessita te re-compilation of clients of the module. In C and C++,
since all we have to track dependencies is file modification time, there's
simply no way for the compiler to know if a change requires recompilation of
clients or not, so it must take the conservative route and assume that all
changes (to a shared file) are important to clients.

The fact that C++ puts the implementation of the class, even if it's
private, into the field of view of clients further aggravates the situation.
In that regard, I'm not sure that .NET has done enough to shield clients
from internals changes to classes they consume, but it's a big step in the
right direction.


I do not know much on the subject, but in.NET specifically, one may
create dlls and use them, with no recompilation needed.

--
Ioannis Vranos
Nov 17 '05 #25
Ioannis Vranos wrote:
I do not know much on the subject, but in.NET specifically, one may
create dlls and use them, with no recompilation needed.


Exactly - that's why I say it's a step in the right direction. I'm not sure
it's the complete answer, but it's better than #include.

-cd
Nov 17 '05 #26
See inline ***.

"Ioannis Vranos" <iv*@guesswh.at .grad.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Willy Denoyette [MVP] wrote:
Managed C++/CLI producing 25% faster code than C#. Any resources that
prove this claim?

Mentioned in:

http://microsoft.sitestream.com/Tech...V333_Sutte.ppt
http://www.accu.org/conference/prese..._(keynote).pdf
and in various other places.

****
Ok, but this doesn't prove the claim, it's just the source of all claims. I
was there at teched and when asked about the 25% difference, the answer I
got was - if this was true, the C# compiler team would have done a lousy job
:-).
Anyway, all benchmarks I have done indicate differences in performance in
between +5% and -5% (yes, sometimes C# is faster).
For real world applications the performance difference is neglectable, don't
forget that the BCL is all written in C#, and the CLR just sits in top of
the same C runtime and Win32.
Don't get me wrong C++/CLI is a great language extension and C++ my language
of choice, but execution speed is not the differentiator when comparing with
other managed languages.

Also many articles mention that VC++ compiler produces compile-time
optimised code in addition to CLR runtime MSIL optimisation, and has much
more time to optimise the code than CLR.

*** Why? What stops the C# compiler to take more time to optimize? Do you
think the C# compiler team is sleeping now?


Like this:

http://msdn.microsoft.com/msdnmag/is...5/default.aspx

"While the just-in-time (JIT) compiler today analyzes for optimizations at
run time, allowing the C++ compiler to optimize during the initial
compilation can still provide significant performance benefits (the C++
compiler has much more time to perform its analysis than does the JIT)."

*** The same goes for C# isn't it?

Willy.
Nov 17 '05 #27
> >> Managed C++/CLI producing 25% faster code than C#. Any resources that
prove this claim?
...
Mentioned in:

http://microsoft.sitestream.com/Tech...V333_Sutte.ppt http://www.accu.org/conference/prese..._(keynote).pdf

...
****
Ok, but this doesn't prove the claim, it's just the source of all claims.

I was there at teched and when asked about the 25% difference, the answer I
got was - if this was true, the C# compiler team would have done a lousy job :-).
Anyway, all benchmarks I have done indicate differences in performance in
between +5% and -5% (yes, sometimes C# is faster).
For real world applications the performance difference is neglectable, don't forget that the BCL is all written in C#, and the CLR just sits in top of
the same C runtime and Win32.
Don't get me wrong C++/CLI is a great language extension and C++ my language of choice, but execution speed is not the differentiator when comparing with other managed languages.

I don't know how they tested this, but I do not see any visible speed
difference between managed C++ and C#
I base this experience because I just porter 80% of my managed C++ code to
C# and I do not notice any difference.
This C++ code ported to C# is 'exactly' the same code that I compare with.
The biggest diference is that for managed structures I had to add 'new' for
C# where I did not need this for C++.
I assume in some parts I lose speed and in other parts I gain speed.

The biggest speed gain is in development. The build takes now seconds while
the C++ version takes minutes.
No more fighting with wierd compiler and linker errors, the C# underlines in
red and blue where I have to fix.
Commenting funtions is now actually fun. :-)
Intellisense is lightning fast.
And a far smaller destination dll. :-)

Don't worry, I still use unmanaged C++ for the really preformance critical
functionality. :-)
Nov 17 '05 #28
Carl Daniel [VC++ MVP] wrote:
Ioannis Vranos wrote:
I do not know much on the subject, but in.NET specifically, one may
create dlls and use them, with no recompilation needed.

Exactly - that's why I say it's a step in the right direction. I'm not sure
it's the complete answer, but it's better than #include.


Well each mechanism is different. The #include mechanism is for
compile-time source code inclusion, while the #using mechanism is for
precompiled library use in run time.

--
Ioannis Vranos
Nov 17 '05 #29
Olaf Baeyens wrote:
I don't know how they tested this, but I do not see any visible speed
difference between managed C++ and C#
I base this experience because I just porter 80% of my managed C++ code to
C# and I do not notice any difference.
This C++ code ported to C# is 'exactly' the same code that I compare with.
The biggest diference is that for managed structures I had to add 'new' for
C# where I did not need this for C++.
I assume in some parts I lose speed and in other parts I gain speed.

The biggest speed gain is in development. The build takes now seconds while
the C++ version takes minutes.
No more fighting with wierd compiler and linker errors, the C# underlines in
red and blue where I have to fix.
Commenting funtions is now actually fun. :-)
Intellisense is lightning fast.
And a far smaller destination dll. :-)

Don't worry, I still use unmanaged C++ for the really preformance critical
functionality. :-)


I guess the major difference will be in C++/CLI and VC++ 2005 and
afterwards.
An interesting article I came across yesterday:

http://blogs.msdn.com/branbray/archi.../07/51007.aspx

--
Ioannis Vranos
Nov 17 '05 #30

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

Similar topics

3
949
by: Andy Tran | last post by:
I built a system using mysql innodb to archive SMS messages but the innodb databases are not keeping up with the number of SMS messages coming in. I'm looking for performance of 200 msgs/sec where 1 msg is 1 database row. I'm running on Red Linux: 2.4.20-8bigmem #1 SMP Thu Mar 13 17:32:29 EST 2003 i686 i686 i386 GNU/Linux The machine has dual CPU and 2G of RAM.
14
3707
by: Ron Johnson | last post by:
Hi, While on the topic of "need for in-place upgrades", I got to think- ing how the pg_restore could be speeded up. Am I wrong in saying that in the current pg_restore, all of the indexes are created in serial? How about this new, multi-threaded way of doing the pg_restore: 0. On the command line, you specify how many threads you want.
8
2491
by: murphy | last post by:
I'm programming a site that displays info from AWS Commerce Service 4.0. At each change of the asp.net application the first load of a page that uses the web service takes 30 seconds. Subsequent calls are snappy. From what I've learned this overhead is for processing the wsdl file (which has of course not changed). The file is large, 2200 lines. Is there a way to use this file locally on the web server or cache the result of the...
1
1344
by: Brian Basquille | last post by:
Hello all. Have been working on the Air Hockey game on and off for a couple of weeks now.. but have had plenty of other assignments to keep me busy along with it. But i would like some suggestions on improving it. It's far from fully working, but some suggestions on the following would be great. Please download it from: http://homepage.eircom.net/~basquilletj/AirHockey.rar.
1
1139
by: Robin | last post by:
For an asp.net project that is deployed to a load balanced web servers, are there any performance changes that can be made in .Net runtime or IIS 6? Also are there any additional tips for reviewing the asp.net (VB) code for improving performance?
1
1994
by: Larry Neylon | last post by:
Hi, I'm working on a VBScript application on IIS6 and I'm looking for some advice about the best way of replacing or improving session variable usage. The application is in a secure extranet environment. Currently the application has a search customers page with 10 search fields which list the results below the search fields. The requirement for this screen was that the user could return to this result page at any point from any page...
1
1519
by: mjheitland | last post by:
Hello, does anyone know if an update is available (or at least planned) for the much cited standard reference IMPROVING .NET APPLICATION PERFORMANCE AND SCALABILITY? link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenet.asp or as a download:
5
2433
by: Rahul B | last post by:
Hi, We have been migrating to DB2 and it has been the trend that the application has become somewhat slow. It could be because of the application problems or it could be because i am not very aware of how to try to improve the performance of the DB2. The only thing i am aware is about the RunStats utility. Can somebody give me various steps that i can take to try to improve
3
12326
by: Michel Esber | last post by:
Hello, Environment: DB2 LUW v8 FP15 / Linux I have a table with 50+ Million rows. The table structure is basically (ID - Timestamp). I have two main applications - one inserting rows, and the other reading/deleting rows. The 'deleter' application runs a MIN/MAX (timestamp) for each ID and, if the difference between min/max is greater than 1h, it reads all
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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
5860
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
4366
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
4615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
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
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1999
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.