473,395 Members | 1,379 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,395 software developers and data experts.

Why is C# 500% slower than C++ on Nested Loops ???

http://www.tommti-systems.de/go.html...enchmarks.html
Why is C# 500% slower than C++ on Nested Loops ???
Will this problem be solved in the future???
Nov 17 '05 #1
17 3003
Peter,

Well ... you will note it's more than 3 times faster than Java, which is
a much more appropriate comparison. C++ and C# are different tools for
different purposes, and are most usefully compared to their peers, not
to each other.

That said, you're right that the gap was particularly wide in this case.
I can only guess that C# doesn't have as many compiler optimizations
in place as C++ that would benefit this particular scenario.

--Bob

Peter Olcott wrote:
http://www.tommti-systems.de/go.html...enchmarks.html
Why is C# 500% slower than C++ on Nested Loops ???
Will this problem be solved in the future???

Nov 17 '05 #2

"Bob Grommes" <bo*@bobgrommes.com> wrote in message news:uq**************@TK2MSFTNGP15.phx.gbl...
Peter,

Well ... you will note it's more than 3 times faster than Java, which is a much more appropriate comparison. C++ and C# are
different tools for different purposes, and are most usefully compared to their peers, not to each other.

That said, you're right that the gap was particularly wide in this case. I can only guess that C# doesn't have as many compiler
optimizations in place as C++ that would benefit this particular scenario.

--Bob

Peter Olcott wrote:
http://www.tommti-systems.de/go.html...enchmarks.html
Why is C# 500% slower than C++ on Nested Loops ???
Will this problem be solved in the future???

I am estimating that it will be a problem that is easy to fix.
I am making this estimate on the basis of how well C# did
on the other benchmarks, compared to Visual C++.
Nov 17 '05 #3
Peter,
Why is C# 500% slower than C++ on Nested Loops ???


If you are really worried about performance and still want to use managed
code, please read up on "ngen".

Regards,

Randy
Nov 17 '05 #4
Bob Grommes <bo*@bobgrommes.com> wrote:
Well ... you will note it's more than 3 times faster than Java, which is
a much more appropriate comparison.


Which result are you looking at? Looking at the "nested loops" column
(the one the OP is talking about) I can only see Java being faster than
C# - and in some cases the Java is faster than the C++.

Also note that the released Java 1.5 isn't part of the results, and
neither is the IBM JVM (which I believe would be a lot better at the
trig - I don't know about the other results).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5
Randy A. Ynchausti <ra*************@msn.com> wrote:
Why is C# 500% slower than C++ on Nested Loops ???


If you are really worried about performance and still want to use managed
code, please read up on "ngen".


That makes startup faster, but it actually reduces the number of
optimisations the JIT performs.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
On Fri, 26 Aug 2005 21:29:31 -0500, "Peter Olcott" <ol****@att.net>
wrote:
I am estimating that it will be a problem that is easy to fix.
Uh, no. Writing a good optimizer is pretty hard. The current
iterations of Visual C++ and Intel C++ had over a decade of labor
poured into them to make them as fast as they are.
I am making this estimate on the basis of how well C# did
on the other benchmarks, compared to Visual C++.


You're comparing different benchmarks for languages with very
different infrastructures! You can't make any cross-inferences from
one benchmark to another in this case.
--
http://www.kynosarges.de
Nov 17 '05 #7
"Jon Skeet [C# MVP]" <sk***@pobox.com> ha scritto nel messaggio
Which result are you looking at? Looking at the "nested loops" column
(the one the OP is talking about) I can only see Java being faster than
C# - and in some cases the Java is faster than the C++.


Java faster than something else?
It's hard to me to figure it out :)

--
..Net Reporting tool: http://www.neodatatype.net
Nov 17 '05 #8

"Peter Olcott" <ol****@att.net> wrote in message
news:RQNPe.2261$UI.1020@okepread05...
http://www.tommti-systems.de/go.html...enchmarks.html
Why is C# 500% slower than C++ on Nested Loops ???
Will this problem be solved in the future???


In general, such kind of micro-benchmarks have little or no value, in this
particular case, it shows that the C# language compiler could have done a
better job in optimizing the IL.
To prove it, here are the results of the nested loop run comparing C++,
C++/CLI and C#.

//C++ native (Compiler version 13.00)
Nested Loop elapsed time: 6048 ms -1804337152
//C++ managed - compiler options /clr /O2 /EHsc (14.00)
Nested Loop elapsed time: 6047 ms -1804337152
//C#
v1.1
Nested Loop elapsed time: 19800 ms - -1804337152
v2.0
Nested Loop elapsed time: 21050 ms - -1804337152

See, the native C++ and managed C++ results are the same, this indicates
that it's not a JIT issue but an IL issue.
When comparing the generated IL of both C# and C++/CLI, it's the C++/CLI
language compiler who did a better job than C#. However, for the
'Exceptions" case, it's C# who is the clear winner (managed code), so
suppose this is the result of the differences in priorities and constraints
set by the different language teams.
Willy.
Nov 17 '05 #9

"Christoph Nahr" <ch************@kynosarges.de> wrote in message news:32********************************@4ax.com...
On Fri, 26 Aug 2005 21:29:31 -0500, "Peter Olcott" <ol****@att.net>
wrote:
I am estimating that it will be a problem that is easy to fix.


Uh, no. Writing a good optimizer is pretty hard. The current
iterations of Visual C++ and Intel C++ had over a decade of labor
poured into them to make them as fast as they are.


Yet, since these mechanisms already exist in code that Microsoft
already owns, it is only a matter of adapting and porting. By very
easy, I am meaning, "just takes a little work", as opposed to
requiring new computer science to be invented.
I am making this estimate on the basis of how well C# did
on the other benchmarks, compared to Visual C++.


You're comparing different benchmarks for languages with very
different infrastructures! You can't make any cross-inferences from
one benchmark to another in this case.
--
http://www.kynosarges.de

Nov 17 '05 #10

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om...
Bob Grommes <bo*@bobgrommes.com> wrote:
Well ... you will note it's more than 3 times faster than Java, which is
a much more appropriate comparison.
Which result are you looking at? Looking at the "nested loops" column
(the one the OP is talking about) I can only see Java being faster than
C# - and in some cases the Java is faster than the C++.


The next to last column on the right of all three tables. On this column
on these tables MS C++ won all but one the fifteen benchmarks.
On this column of these tables C++ consistently beat C# by a factor
of about 500%.
Also note that the released Java 1.5 isn't part of the results, and
neither is the IBM JVM (which I believe would be a lot better at the
trig - I don't know about the other results).

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

Nov 17 '05 #11

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...

"Peter Olcott" <ol****@att.net> wrote in message news:RQNPe.2261$UI.1020@okepread05...
http://www.tommti-systems.de/go.html...enchmarks.html
Why is C# 500% slower than C++ on Nested Loops ???
Will this problem be solved in the future???

In general, such kind of micro-benchmarks have little or no value, in this particular case, it shows that the C# language compiler
could have done a better job in optimizing the IL.
To prove it, here are the results of the nested loop run comparing C++, C++/CLI and C#.

//C++ native (Compiler version 13.00)
Nested Loop elapsed time: 6048 ms -1804337152
//C++ managed - compiler options /clr /O2 /EHsc (14.00)
Nested Loop elapsed time: 6047 ms -1804337152
//C#
v1.1
Nested Loop elapsed time: 19800 ms - -1804337152
v2.0
Nested Loop elapsed time: 21050 ms - -1804337152

See, the native C++ and managed C++ results are the same, this indicates that it's not a JIT issue but an IL issue.
When comparing the generated IL of both C# and C++/CLI, it's the C++/CLI language compiler who did a better job than C#. However,
for the


That is very helpful information. That provides me with just
the sort of answer that I was looking for. I wanted to know
whether or not there is any inherent property of the .NET
architecture that prevented it from executing the fastest possible
code. Your little experiment would seem to prove that the
answer is no.
'Exceptions" case, it's C# who is the clear winner (managed code), so From the tables on the link that I provided, C# was consistently
400% slower than C++.
suppose this is the result of the differences in priorities and constraints set by the different language teams.
Willy.

Nov 17 '05 #12

"Peter Olcott" <ol****@att.net> wrote in message
news:7qYPe.2271$UI.450@okepread05...

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

"Peter Olcott" <ol****@att.net> wrote in message
news:RQNPe.2261$UI.1020@okepread05...
http://www.tommti-systems.de/go.html...enchmarks.html
'Exceptions" case, it's C# who is the clear winner (managed code), so

From the tables on the link that I provided, C# was consistently
400% slower than C++.


I was comparing C# and C++/CLI (both managed code) where C# is twice as fast
as C++/CLI, NOT C# and native C++!

Willy.
Nov 17 '05 #13

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message news:Ol****************@TK2MSFTNGP10.phx.gbl...
'Exceptions" case, it's C# who is the clear winner (managed code), so From the tables on the link that I provided, C# was consistently
400% slower than C++.


I was comparing C# and C++/CLI (both managed code) where C# is twice as fast as C++/CLI, NOT C# and native C++!


Can you post these results please?
Thanks again for your help. The first answer that you
provided has proven to me the .NET development will
eventually replace all development on the Windows platform.
..NET is a superb Rapid Application Development architecture.


Willy.

Nov 17 '05 #14

"Peter Olcott" <ol****@att.net> wrote in message
news:WO_Pe.2276$UI.751@okepread05...

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:Ol****************@TK2MSFTNGP10.phx.gbl...
'Exceptions" case, it's C# who is the clear winner (managed code), so
From the tables on the link that I provided, C# was consistently
400% slower than C++.

I was comparing C# and C++/CLI (both managed code) where C# is twice as
fast as C++/CLI, NOT C# and native C++!


Can you post these results please?
Thanks again for your help. The first answer that you
provided has proven to me the .NET development will
eventually replace all development on the Windows platform.
.NET is a superb Rapid Application Development architecture.


Why would you need those results to prove that to you?
If the code inside was actually doing anything - dealing with a database or
the GUI or any other I/O, responding to events, whatever, then you'd have a
hard time even measuring any performance penalty. (You'd probably find the
C# faster than native C++, if both were coded ideomatically - and you'd
certainly find the C# easier to write and read and be free of most memory
issues.) If you're trying to predict the weather or code the inner loop of
your renderer, then you're using the wrong tool and you should code that 1%
of your program (after profiling) in native code.

Even so, it's rarely the technical merits alone that decide if a language
will be a success.

m


Willy.


Nov 17 '05 #15

"Mike" <vi********@yahoo.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl...

"Peter Olcott" <ol****@att.net> wrote in message news:WO_Pe.2276$UI.751@okepread05...

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message news:Ol****************@TK2MSFTNGP10.phx.gbl...
> 'Exceptions" case, it's C# who is the clear winner (managed code), so
From the tables on the link that I provided, C# was consistently
400% slower than C++.
I was comparing C# and C++/CLI (both managed code) where C# is twice as fast as C++/CLI, NOT C# and native C++!
Can you post these results please?
Thanks again for your help. The first answer that you
provided has proven to me the .NET development will
eventually replace all development on the Windows platform.
.NET is a superb Rapid Application Development architecture.


Why would you need those results to prove that to you?


You have generally shown that the performance of code is dependent upon the
code generator, and optimizer rather than any inherent features of the .NET
architecture. The one exception to this seems to be "exceptions." I want
to fully understand why this might be.
If the code inside was actually doing anything - dealing with a database or the GUI or any other I/O, responding to events,
whatever, then you'd have a hard time even measuring any performance penalty. (You'd probably find the
I have developed a system that I am planning on porting the C# .NET
architecture. It is a system rather than application program. Its performance
requirements are based on real-time response rate. It is very computationally
intensive. Far greater than 99% of its time is spent performing computations.
From the results that you provided, in the worst case scenario I can
switch to C++ .NET from C# .NET, to achieve my required performance.
I want to completely verify this before I spend too much time learning .NET
C# faster than native C++, if both were coded ideomatically - and you'd certainly find the C# easier to write and read and be free
of most memory issues.) If you're trying to predict the weather or code the inner loop of your renderer, then you're using the
wrong tool and you should code that 1% of your program (after profiling) in native code.

Even so, it's rarely the technical merits alone that decide if a language will be a success.

m


Willy.



Nov 17 '05 #16
Peter Olcott <ol****@att.net> wrote:
Bob Grommes <bo*@bobgrommes.com> wrote:
Well ... you will note it's more than 3 times faster than Java, which is
a much more appropriate comparison.


Which result are you looking at? Looking at the "nested loops" column
(the one the OP is talking about) I can only see Java being faster than
C# - and in some cases the Java is faster than the C++.


The next to last column on the right of all three tables. On this column
on these tables MS C++ won all but one the fifteen benchmarks.
On this column of these tables C++ consistently beat C# by a factor
of about 500%.


But C# doesn't beat Java there, which Bob said it did. (Unless he meant
that C++ was still beating Java, in which case the comment was accurate
but misleading - I don't see why comparing Java and C++ is more
appropriate than comparing C# and C++.)

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

http://www.cuj.com/documents/s=9816/...kschlegel.html

Thomas
Nov 17 '05 #18

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

Similar topics

77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
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: 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...
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...
0
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,...
0
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...
0
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...

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.