Jump to content

  • Log In with Google      Sign In   
  • Create Account


C++ or C#?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
51 replies to this topic

#21 Rob Loach   Moderators   -  Reputation: 1500

Like
0Likes
Like

Posted 20 October 2006 - 09:04 AM

Quote:
Original post by NIm
One note: I've never fooled with C#, but I understand that it's harder to write cross platform code with it. I'm not sure though. Will someone either back me up or shut me up?
Incorrect, compiling with Mono will give you an executable file that you can use on all Mono-compatible platforms (Linux, Windows, Mac, etc). Mono has implemented most of both .NET 1.1 and 2.0.

Rob Loach [Website] [Projects] [Contact]

Sponsor:

#22 DrEvil   Members   -  Reputation: 1102

Like
0Likes
Like

Posted 20 October 2006 - 09:14 AM

Question about Mono from a Mono newbie.

An app compiled with mono can be run as-is on other platforms? As in, I compile a Mono app in windows, I can run that executable in OSX, Linux, other mono supported platforms? I don't have to recompile or anything? The target platform just needs mono installed? Just trying to clarify if thats what you mean. Thanks

J

#23 Flimflam   Members   -  Reputation: 657

Like
0Likes
Like

Posted 20 October 2006 - 09:34 AM

Quote:
Original post by Promit
Quote:
Original post by Kixdemp
I prefer C# by a million times, C++ is too complicated, but how would the performance be affected if I do it in C#?
Performance would probably be (significantly?) better in C#.


While I understand why you answered the way you did, I think the way you said it merely will cause massive arguments. If he prefers C# a million times over, of course his C# code will wind up being better than his C++ code. But the way you said it sounded as if you were implying that C# is a (significantly?) faster language in general, which is where all the fighting will come in.

I'd consider being a little less vague about your commentary. It'll make these kinds of topics a better place to be in and not one to avoid.

I love both languages really, but I never really liked Managed DirectX that much. (mainly because it's so similar yet so different from Unmanaged DirectX, leading to confusing moments)

#24 Surg   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 October 2006 - 09:47 AM

When I said "Are you trying to start a battle" I was talking about how saying things like that without explaining yourself often start battles.

Oh, and look what happened.

#25 BlueHabu   Members   -  Reputation: 106

Like
0Likes
Like

Posted 20 October 2006 - 10:35 AM

"C# is faster than C++". That seem pretty bold to me

It would seem with all the "expert engineers/programmers" someone would confirm that C# is faster than C++ by publicly posting their testing environments for scrutiny. When the hypothesis that C# is faster than C++ is proven, it would no longer be considered irresponsible to make such a claim.

It seems like there are plenty "C# is God's native tongue" people with an agenda so I don't see any lack of motivation to prove their point. However, I have seen no effort to do so.

#26 Promit   Moderators   -  Reputation: 6604

Like
0Likes
Like

Posted 20 October 2006 - 11:01 AM

Quote:
Original post by BlueHabu
"C# is faster than C++". That seem pretty bold to me
It's also a claim that doesn't appear anywhere in this thread.
Quote:
However, I have seen no effort to do so.
I can't speak for others, but I feel no obligation to prove myself to others. I've put a lot of time into researching performance. If others aren't willing to spend even a little effort on the matter, that's their problem. I just don't want their ignorance polluting these discussions.

Anyway, the answer had nothing to do with the languages and everything to do with the poster's experience. C++, C#, and most other environments are performance minefields even when you know what you're doing.

#27 Alpha_ProgDes   Crossbones+   -  Reputation: 4688

Like
0Likes
Like

Posted 20 October 2006 - 11:31 AM

Quote:
Original post by DrEvil
Question about Mono from a Mono newbie.

An app compiled with mono can be run as-is on other platforms? As in, I compile a Mono app in windows, I can run that executable in OSX, Linux, other mono supported platforms? I don't have to recompile or anything? The target platform just needs mono installed? Just trying to clarify if thats what you mean. Thanks

J

Another question, from a (lower than) newbie. If I make a project in Mono and I have .NET installed on my computer. Can .NET running my Mono-made program? Does Mono depend on .NET or does it have it's own interpreter/VM?

#28 zedzeek   Members   -  Reputation: 528

Like
0Likes
Like

Posted 20 October 2006 - 01:28 PM

Quote:
Original post by BlueHabuIt would seem with all the "expert engineers/programmers" someone would confirm that C# is faster than C++ by publicly posting their testing environments for scrutiny. When the hypothesis that C# is faster than C++ is proven, it would no longer be considered irresponsible to make such a claim.

well i think 99% of the studies show that c++ or c are faster than c#
whilst that maybe the case, as has been pointed out, for the original poster, since he prefers c# then theyre prolly gonna get more perfoamnce out of it than c++



#29 mikeman   Members   -  Reputation: 2195

Like
0Likes
Like

Posted 20 October 2006 - 01:47 PM

Quote:
Original post by BlueHabu
"C# is faster than C++". That seem pretty bold to me

It would seem with all the "expert engineers/programmers" someone would confirm that C# is faster than C++ by publicly posting their testing environments for scrutiny. When the hypothesis that C# is faster than C++ is proven, it would no longer be considered irresponsible to make such a claim.

It seems like there are plenty "C# is God's native tongue" people with an agenda so I don't see any lack of motivation to prove their point. However, I have seen no effort to do so.


If such a survey is done, it should be 'complete', because only then it would carry some meaning. It should include a performance/cost ratio, where cost is the money or hours spend to develop each program. When we say 'faster', do we mean the maximum or the "average"? If I need 3 months to write a C++ program that is 10% faster than the program I would write in C# in one month, and if given one month the C++ program would actually perform worse than the C# one, then which is faster? We're not talking about,say, Python(which I love) or compiled vs interpreted code here, where the answer seems obvious. C# programs are also JIT-compiled into native code.

Note, I don't particularly(or at all) like C#, but this seems a logical question to me.



#30 MaulingMonkey   Members   -  Reputation: 1556

Like
0Likes
Like

Posted 20 October 2006 - 03:04 PM

Quote:
Original post by BlueHabu
"C# is faster than C++". That seem pretty bold to me


____ is faster than ____ is basically by definition bold to the point of being wrong. Given one program in one language, I can guarantee I can make you a slower one in any other language. As such, I can "prove" any language is "slower" than any other - and conversly, that any chosen language is "faster" than any other by showing slower examples in any other language.

The current state of compiler technology is that you can eventually produce, if you're an expert, faster programs in C++ than just about any other language, probably.

The fact that in many circumstances you'll have to spend more time optimizing parts of that code than will ever be spent actually executing it on all of the computers it is installed on, for that product's entire shelf life, to achieve this "pinicle of optimization", is a footnote usually skimmed or coughed over in barely audiable tones by those trying to prove some sort of point about C++ being "omg teh superiorz".

And for me? I'm pretty sure I'd produce a more optimized C++ program than a C# one in a given alotment of time for the majority of situations. Not because C++ is somehow superior, but because I've been using it since before it was even standardized - about 10 years - whereas my knowledge of C# is at best fairly laughable.

And this exact same kind of sentiment is what just about everyone who's voiced an opinion here. We're not claiming C# is faster than C++. We're just claiming it's faster for the OP.

Quote:
It would seem with all the "expert engineers/programmers" someone would confirm that C# is faster than C++ by publicly posting their testing environments for scrutiny.


If only it were that simple. Problem is, it's impossible to create the perfect comparison, and even those done by experts are all too often badly flawed - and contradictory even when they arn't. It's the age old question of which is a better tool: the saw or the hammer? The answer depends entirely on wheither you're trying to cut a plank or nail them together. Only in the realm of programming, entire toolsets are heavily intertwined, and even the simple problems tend to be a lot more complex.


#31 SimonForsman   Crossbones+   -  Reputation: 6035

Like
0Likes
Like

Posted 20 October 2006 - 04:04 PM

as it is , performance wise C# is at roughly the same level as the java server vm,
which places it slightly behind modern C and C++ compilers,

however this assumes that the C and C++ compilers optimizes for the target platform.

for a dev its easy to make a C++ program run faster on his own computer than an equivalent C# program since the dev can recompile the program and optimize it for his hardware.

This is also true for most opensource applications,

however for closed source projects you might actually get better performance by using JIT compilation since that would allow your end-user to easily optimize the executable for his own hardware. (with java and C# this is done automatically the first time the user runs the software),

the .NET JIT compiler keeps improving, performance gets better and better,
and one important aspect of that is: YOU don't have to do anything when a better runtime gets released. with C++ you would need to buy a new compiler, re-build the project and release a new version.

and finally the most important factor:
managed languages save alot of time, are easier to use, etc,
thus you can spend more time optimizing your algoritms. (the algoritms you use is what makes the real difference between a fast and slow application).

some AAA games today even use interpreted scripting languages quite heavily (python for example) even though they are reasonably slow. WHY ? Simply because its easy and flexible and you don't need every last bit of performance when the game is limited by the GPU anyway.

as for the OP:s question.

if you write everything in C# you might end up using 5-10% more cpu time than you would if you wrote everything in perfectly optimized C++, for a game like liero or soldat that could translate to 4500fps instead of 5000fps :)

for a graphically advanced game you'd probably be GPU bound so it wouldn't matter at all.

for heavy physics etc you could always use a native unmanaged physics engine and thus that wouldn't matter either.

Thus just use C# , C++ is great for writing device drivers, physics engines, a program to find large prime numbers, etc, for actual game logic its mostly an unnecessary hassle.

if you are really worried about performance you can have a look at this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/fastmanagedcode.asp

it contains some tips and instructions for how to write faster managed code using .NET.

quite many of those hints are valid for unmanaged code aswell though.

the key hints are:
keep memory footprints small to ensure that as much real data as possible fits into the cache. (being forced to wait for a memory load is extremely expensive).
Reflection is slooooooow. (its also very useful though)

#32 Surg   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 October 2006 - 06:11 PM

Quote:
Original post by SimonForsman
as it is , performance wise C# is at roughly the same level as the java server vm,
which places it slightly behind modern C and C++ compilers,

however this assumes that the C and C++ compilers optimizes for the target platform.

for a dev its easy to make a C++ program run faster on his own computer than an equivalent C# program since the dev can recompile the program and optimize it for his hardware.

This is also true for most opensource applications,

however for closed source projects you might actually get better performance by using JIT compilation since that would allow your end-user to easily optimize the executable for his own hardware. (with java and C# this is done automatically the first time the user runs the software),

the .NET JIT compiler keeps improving, performance gets better and better,
and one important aspect of that is: YOU don't have to do anything when a better runtime gets released. with C++ you would need to buy a new compiler, re-build the project and release a new version.

and finally the most important factor:
managed languages save alot of time, are easier to use, etc,
thus you can spend more time optimizing your algoritms. (the algoritms you use is what makes the real difference between a fast and slow application).

some AAA games today even use interpreted scripting languages quite heavily (python for example) even though they are reasonably slow. WHY ? Simply because its easy and flexible and you don't need every last bit of performance when the game is limited by the GPU anyway.

as for the OP:s question.

if you write everything in C# you might end up using 5-10% more cpu time than you would if you wrote everything in perfectly optimized C++, for a game like liero or soldat that could translate to 4500fps instead of 5000fps :)

for a graphically advanced game you'd probably be GPU bound so it wouldn't matter at all.

for heavy physics etc you could always use a native unmanaged physics engine and thus that wouldn't matter either.

Thus just use C# , C++ is great for writing device drivers, physics engines, a program to find large prime numbers, etc, for actual game logic its mostly an unnecessary hassle.

if you are really worried about performance you can have a look at this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/fastmanagedcode.asp

it contains some tips and instructions for how to write faster managed code using .NET.

quite many of those hints are valid for unmanaged code aswell though.

the key hints are:
keep memory footprints small to ensure that as much real data as possible fits into the cache. (being forced to wait for a memory load is extremely expensive).
Reflection is slooooooow. (its also very useful though)


I could offer a counter point for each of your points, and someone could offer one for each of mine, so and so forth.


#33 paulecoyote   Members   -  Reputation: 1060

Like
0Likes
Like

Posted 20 October 2006 - 10:36 PM

For goodness sake, another one of these threads?!?!

Kixdemp - did you even bother looking around for the various threads already around here, and realise what an inonixious question that is? I'll grant you that it is for a specific project... but still.

If you like C# and comfortable in it, do it in C#. A soldat clone is hardly going to be pushing boundaries of either language. You sound like you are more keen to make the game then do it as an academic exercise to learn C++. Think about it this way, you could write poor performing code in both C++ or C# - but in C# you would have the experience and understanding to fix the performance problems.

For you it sounds like the right choice would be C#. For someone with C++ experience (and actually wrote something about liking the language rather then finding it too complex), the right choice would be C++.

#34 BlueHabu   Members   -  Reputation: 106

Like
0Likes
Like

Posted 21 October 2006 - 07:14 AM

Quote:
Original post by Promit
Quote:
Original post by BlueHabu
"C# is faster than C++". That seem pretty bold to me
It's also a claim that doesn't appear anywhere in this thread.

You are right you said
Quote:
Original post by Promit
Performance would probably be (significantly?) better in C#.
Since this is "C++ or C#?" thread what are you comparing if not C++ performance to C#?

Quote:
Original post by PromitI can't speak for others, but I feel no obligation to prove myself to others. I've put a lot of time into researching performance. If others aren't willing to spend even a little effort on the matter, that's their problem. I just don't want their ignorance polluting these discussions.


Well that’s too bad but that’s what computer SCIENTISTS do. We research ideas and topics and post our results. You would think if you had all this research it would be simple for you to post it and if it was proved correct you would receive many accolades for resolving this very volatile and heated issue.

If you are so concerned about the "their ignorance polluting these discussions" then PROVE them wrong. You say you have all this research share it. Let other look at and learn form it. Let others make it better.

On a side note: Does anyone not want to see Promit prove C# is faster than C++?

If you look at the latest issue of Communications of the ACM you will see a nice paper called "What makes a good programmer" The one trait the article said was important yet I thought most programmers lacked was objectiveness. IMO, this lacking trait is polluting these forums more than anything else.

To whoever: Feel free to knock me down some more in ratings. I really dont put much stock in it

#35 joew   Crossbones+   -  Reputation: 3648

Like
0Likes
Like

Posted 21 October 2006 - 07:32 AM

Quote:
Original post by BlueHabu
Since this is "C++ or C#?" thread what are you comparing if not C++ performance to C#?

Actually you have a reading comprehension problem and that is why you are now trying to argue. This is not a "C++ or C#" thread, it is a "C++ or C# for this specific user" thread as stated in the beginning. The user stated he already knows C# and prefers to use it, therefore you just didn't read the full question carefully.

Quote:
Well that’s too bad but that’s what computer SCIENTISTS do. We research ideas and topics and post our results.

Actually that is incorrect. Computer science has absolutely nothing to do with benchmarking compiled source code from various languages. The actual point of computer science (hence the science part) is to build algorithms, factor down algorithms, create larger algorithms based on smaller, and put those together to form a solution for a problem.

Quote:

You would think if you had all this research it would be simple for you to post it and if it was proved correct you would receive many accolades for resolving this very volatile and heated issue.

This is only a volitile or heated issue for someone uneducated or evangelical with a certain technology. Anybody with half a brain would be able to realize that this is a multivariable equation. The first component is the actual running speed of a C++ vs. C# application, and the second component is the user's knowledge and ability to use C++ or C#. If you try to argue using only one of those than you have not solved a damn thing. I can't believe it is so hard for people that are supposed to be studying and building algorithms all day to understand this... although I hope it is now clear after my post.

Quote:

If you are so concerned about the "their ignorance polluting these discussions" then PROVE them wrong. You say you have all this research share it. Let other look at and learn form it. Let others make it better.

Once you realize that this is a multivariable problem, and that if you try and measure an "average developers skill with X language" you will realize it than solves nothing for any problem at hand. There is no blanket answer and is completely based on the developer plus the technology.

That is why Promit's answer is so clearly right in this context, because the user has already said that he prefers and is more comfortable with C# (variable 2), and C# is already proven to be nearly the speed of a C++ application in a vacuum where both are coded in exact efficiency (variable 1). Therefore it is quite easy to see that the OP will have better performance using C#.

Quote:

On a side note: Does anyone not want to see Promit prove C# is faster than C++?

I just proved it. Also if I still had the link (which I once posted here) it showed the Axiom Engine (C# port of Ogre) running faster than Ogre in the majority of cases. Is this because C# is natively faster? Of course not it is because the users knew how to correct some of the mistakes made in Ogre. Also I rewrote a C++ engine in C# at a place I was employed and it turned out to run faster... again due to refactoring and fixing (therefore proving the need for variable 2).

Quote:

If you look at the latest issue of Communications of the ACM you will see a nice paper called "What makes a good programmer" The one trait the article said was important yet I thought most programmers lacked was objectiveness. IMO, this lacking trait is polluting these forums more than anything else.

Actually the most important thing for a developer would be discrete mathematics, algorithms, and logic (as that is the actual computer science.. not the programming part). And it looks like a lot of people don't understand how to break something down, as yourself and others in this thread first did not break the correct question out of the initial post, and furthermore didn't see the equation was multivariable with the second being highly variate to the actual problem (user).

Quote:

To whoever: Feel free to knock me down some more in ratings. I really dont put much stock in it

I wouldn't dare rate you down. Your post was perfect for me to explain the actual concepts and reasoning, I thank you for it actually.

#36 Rob Loach   Moderators   -  Reputation: 1500

Like
0Likes
Like

Posted 21 October 2006 - 11:04 AM

Quote:
Original post by DrEvil
An app compiled with mono can be run as-is on other platforms? As in, I compile a Mono app in windows, I can run that executable in OSX, Linux, other mono supported platforms? I don't have to recompile or anything? The target platform just needs mono installed? Just trying to clarify if thats what you mean. Thanks
Yup, that's the idea! Mono's JIT compiler is pretty amazing [smile] .

Quote:
Original post by Alpha_ProgDes
Another question, from a (lower than) newbie. If I make a project in Mono and I have .NET installed on my computer. Can .NET running my Mono-made program? Does Mono depend on .NET or does it have it's own interpreter/VM?
Mono and .NET can be installed side-by-side.... Hmmm, I just built all of the Tao examples in Mono, and then uninstalled Mono, and they still ran fine. Maybe Mono mimics .NET byte code..... Mono has its own JIT compiler, which you run by using: "mono MyProgram.exe". The neat thing is that you can run most .NET applications through Mono without any problems without even recompiling for Mono. It's really neat.... Just run "mono MyDotNetProgram.exe" in the Mono console application and you'll see. Works in all Mono platforms too...

Rob Loach [Website] [Projects] [Contact]

#37 Promit   Moderators   -  Reputation: 6604

Like
0Likes
Like

Posted 21 October 2006 - 11:42 AM

Quote:
Original post by BlueHabu
You say you have all this research share it. Let other look at and learn form it. Let others make it better.
Partial list. Knock yourself out.

Quote:
Also if I still had the link (which I once posted here) it showed the Axiom Engine (C# port of Ogre) running faster than Ogre in the majority of cases.
Linktronix. It looks like C# falls behind in the cases that are very computationally intense (not a big surprise). There's techniques to relieve that in C, or you can even go ahead and rewrite the relevant bits in C++ (with SSE niceness and such) if so desired.

#38 joew   Crossbones+   -  Reputation: 3648

Like
0Likes
Like

Posted 22 October 2006 - 05:49 AM

Cool thanks for that Ogre/Axiom link Promit, I thought it was gone for good :) Also note that at the time of the benchmarks Axiom was using v1.0 of the .NET framework/C# and so no generics, float performance, etc... which is quite impressive imo.

#39 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 22 October 2006 - 08:08 AM

why commercial game write by c++?
why graphic softwar write byc++?(3dsmax-photoshap-...)

#40 Promit   Moderators   -  Reputation: 6604

Like
0Likes
Like

Posted 22 October 2006 - 08:40 AM

Quote:
Original post by Anonymous Poster
why commercial game write by c++?
why graphic softwar write byc++?(3dsmax-photoshap-...)
Well keep in mind that C# is a rather new development, and though Java's been around for longer it's only recently benefited from some of the cutting edge technologies in JIT.

5 years ago, Java performance was questionable at best, and C# was not yet a stable 1.0 release. The big applications now have longer timelines than that. Consider your examples. 3DS Max originally grew as a revision of the original Autodesk product called 3D Studio, a program written for 16 bit DOS in a time when the very concept of consumer 3D hardware was a laughable dream. Photoshop 1.0 was released in 1990 for the Mac OS -- that'd be System 6 at the time. No hardware accelerated drawing, cooperative multitasking environment, etc. Hell, both of these started out as, and may still be predominantly C codebases, not C++. (In fact, the early versions of both of those may have needed considerable assembly code to do what they did.)

Java, in contrast, was created as Gosling's pet project in 1991, and didn't show up as a product until 1995. The JDK releases started properly in 1997.

The very luxury to be able to choose something other than C/C++ is extremely recent. Major large scale applications haven't really had much time to appear, and the ones that have are enterprise level things that most consumers never see. And nobody is going to go back and rewrite millions of lines of mature code in C# just because. That's a recipe for disaster. It's only new projects that can choose. Not to mention that the stigmas surrounding managed code are plentiful, which hasn't helped.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS