• Advertisement

Archived

This topic is now archived and is closed to further replies.

C# is not Fast! Re: Today's Earlier Benchmark

This topic is 4979 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So earlier today I posted a naive floating point benchmark showing that C++ and C# were equally fast. This was an invalid test for many reasons that were pointed out to me. As a follow-up, I have now almost completely rewritten (well, copied mostly) my C# procedural texture generator as a DLL written in C++. I have not even begun to optimize the C++ code (using cosine tables, inlining, caching values, ect...) and already it is performing 5-8 times faster that my C# version. I can generate a 1024x1024 perlin noise field with 5 octaves and cubic interpolation in 1 second. My previous code can take 10 seconds to do this. I anticipate that by the time I am done, it will actually be faster to generate a planet texture on the fly than it will be to load one from disk! So I was very wrong. Moving my intense calculations to C code really helped performance. Though I might point out that my original C# code was horribly inefficient and had a lot of headroom for optimization without changing languages. So it's unclear how much of the performance gain is due to me being much more experienced with writing fast code in C vs. C#. The ultimate winner is everybody, though. I'll be releasing my texture generation code soon, and because I went through the trouble of writing a DLL, you'll be able to plug it into just about anything. This is also not to say that C# is a poor language - I like it a lot. Different tools for different jobs... ---------------------------------------- Let be be finale of seem, seems to me. ---------------------------------------- Shedletsky's Code Library: Open source projects and demos [edited by - Telamon on April 15, 2004 12:48:56 AM]

Share this post


Link to post
Share on other sites
Advertisement
quote:
So it''s unclear how much of the performance gain is due to me being much more experienced with writing fast code in C vs. C#.

And yet you post an almost intentionally inflammatory subject line and speak as if you do know what you are talking about.

Share this post


Link to post
Share on other sites
Was the old thread deleted? Great!

Although your benchmark test shows a complete different result, the postings concerning benchmark tests and other things were true.

C# is fast, however the startup time (first execution of code parts is much slower due to jit compilation). I hope you had that in mind when you did your "benchmark" test.


Have fun
Bunnz
Purple#, a shader-driven game engine for .NET.

Share this post


Link to post
Share on other sites
Yeah, I deleted the other thread when it became obvious it had no value.

Both the C# code and the C++ DLL will be slow the first time it is run, since one needs to be JITed and the other needs to be dynamically linked.

antareus: In fact, I do know what I am talking about. My point was that the huge speedup I acheived should not be viewed as concluding "C# is really slow". I''m sure an experienced .Net programmer could optimize my C# code and make it run twice as fast. But there''s more overhead in C#, so I doubt it''s possible to make the C# code run 5 - 8 faster.

The subject line makes it clear that this is a follow-up post. It is not meant to be inflammatory but rather ironic. I won''t apologize if you missed that.

----------------------------------------
Let be be finale of seem, seems to me.
----------------------------------------

Shedletsky''s Code Library:

Open source projects and demos

Share this post


Link to post
Share on other sites
quote:
the C# code and the C++ DLL will be slow the first time it is run, since one needs to be JITed and the other needs to be dynamically linked.



very clever


Have fun
Bunnz
Purple#, a shader-driven game engine for .NET.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I vote this for the "Most stupid thread of the year award" who''s with me

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Wrong forum! Here is a link to your forum: http://www.gamedev.net/community/forums/forum.asp?forum_id=31

Share this post


Link to post
Share on other sites
quote:
Original post by Oluseyi
This one can now follow suit, as you have no clue how to benchmark.


I used to think you were a competent mod... Oh well, next time, think before you post.

Share this post


Link to post
Share on other sites
quote:
Original post by Puzzler183
I used to think you were a competent mod... Oh well, next time, think before you post.

So, what was valid about the OP''s benchmark, given that he said he didn''t know C# very well? I can write a naive C++ program that would pass large std::string''s by value to the point that C# would end up faster and everyone would be shouting at me about it.

Share this post


Link to post
Share on other sites
quote:
Original post by antareus
So, what was valid about the OP''s benchmark, given that he said he didn''t know C# very well? I can write a naive C++ program that would pass large std::string''s by value to the point that C# would end up faster and everyone would be shouting at me about it.
Hmm, for some reason I think it''d be better to give him some advice instead of telling him to delete his thread. That''s just me, maybe the mods disagree..

Share this post


Link to post
Share on other sites
It''s actually not a benchmark. I don''t think I said it was. Think of it rather as an informal relation of an experience that may be of help to someone considering whether or not to try the same thing.

Share this post


Link to post
Share on other sites
Yeah, civguy, you have a point, but that's GD's resident villain for you.

OP:
Did you use DevPartner on your C# code? A quick session can be really insightful with it. C# may not have much of a learning curve but you still have to invest time in it it seems and relearn how to do stuff. That is what I'm finding.

[edited by - antareus on April 16, 2004 3:57:47 PM]

Share this post


Link to post
Share on other sites
Yikes, so you optimize the C++ version, admit you didn't know how to optimize the C# code, then declare C# as much much slower. *sigh*

"But there's more overhead in C#" Is that something you just read somewhere else and are simply repeating? *sigh #2*

[edited by - leedgitar on April 16, 2004 4:51:16 PM]

Share this post


Link to post
Share on other sites
Telamon: Give up benchmarking, at least for now. You have no idea what you''re doing.

Share this post


Link to post
Share on other sites
If someone else thinks he doesn''t know what he''s doing, they should try writing the same thing the true benchmark way and state the "true" results. Don''t be so negative all the time.

Stay Clausal,

Red Sodium

Share this post


Link to post
Share on other sites
I think the point is he started a thread which said ''C# was fast'', in which it was pointed out his benchmark was bad (and also included a discussion between myself and two other people about the Axiom/OGRE engines and deleting that thread has annoyed me a bit coz i wanted to see where that was going), so he then deleted that thread and started this one where he declares ''C# is not fast!'' (he also Re:''s to a thread which no longer exists), spreading more misinfomation, which although more seasoned programmers can get past could cause a new person to dismiss C# out of hand when it might well be the perfect system for their job.

So, two very bad threads, misinfomation and confusion all around is a perfectly good reason for this thread to be deleted and this whole farce to be forgotten.

Share this post


Link to post
Share on other sites
Well, you could try to redo the Great Computer Language Shootout problems with C# and compare the results. They're a bunch of relatively easy problems to implement, but what's fun to check is how easy is it to do a task in one language compared to another.

Do that and maybe you'll change your mind. Also keep in mind that C# has been out for barely four years, C++ has been available for over 20. I think it's fair to say that maybe the C++ compilers have had more work done on them. For example, if you check out this page, you'll see that the first mention of g++ dates back to 1987. Give another 13 years to C# implementations, and we'll see how really slower it is (or if C-like languages are even still around)


[edited by - GnuVince on April 16, 2004 7:22:14 PM]

Share this post


Link to post
Share on other sites
Most of the people here haven't seen your other post ( I haven't), so post your benchmark, whateveryacallit, and let these master programmers figure out why it's invalid. Then take framerates/loadtimes/etc. and compare them publicly instead of being vague (it's 5-8 times faster).

The true general first seeks victory, then seeks battle
- Sun Tzu

[edited by - Drakkcon on April 16, 2004 11:58:39 PM]

Share this post


Link to post
Share on other sites
Your actually trying to claim that C is 500% to 1000% faster then C#? HaHa, what an idiot.

Dont most real benchmarks show its only around 5%-10% faster?

Share this post


Link to post
Share on other sites
quote:
Original post by Possibility
Your actually trying to claim that C is 500% to 1000% faster then C#? HaHa, what an idiot.

Dont most real benchmarks show its only around 5%-10% faster?


The average is even smaller. Most put C# around 3% slower for well written code/benchmarks.

Share this post


Link to post
Share on other sites
quote:
Original post by haro
The average is even smaller. Most put C# around 3% slower for well written code/benchmarks.
I've seen benchmarks that show C# to be from 10% faster to being 100% (and more) slower, depending on what is tested and what compiler is used. On average I'd say I've seen C# to be 10-25% slower in benchmarks found on the net (though on some tests C# has been so much slower that the estimate probably favours it). It's obvious that C# is fast for some type of stuff and still slow for other stuff. If the program consists mostly of that "other stuff" where C# is slow, simply converting it to C++ line-by-line (if possible) may really give a substantial performance boost.

Even the performance differences between different C++ compilers for different tasks is often way more than 3%, so saying that "most put C# around 3% slower for well written code/benchmarks" is some of the biggest piece of shit I've heard in a while, might I say it's even less qualified than anything Telamon has said. Can you provide any links to back it up?

[edited by - civguy on April 17, 2004 4:40:52 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by civguy
quote:
Original post by haro
The average is even smaller. Most put C# around 3% slower for well written code/benchmarks.
I've seen benchmarks that show C# to be from 10% faster to being 100% (and more) slower

Even the performance differences between different C++ compilers for different tasks is often way more than 3%, so saying that "most put C# around 3% slower for well written code/benchmarks" is some of the biggest piece of shit I've heard in a while



Care to cite a real source that puts C# at 100% (and more) slower? Not that I don't believe you, I've just never seen anything like that. I was pulling the 3% partially off of the Ogre/Axiom comparison and the Quake II .NET project. In case you're not aware, Axiom is a C# graphics engine strongly based off of Ogre which is a graphics engine written in C++. In benchmarking Axiom tends to run quite a bit better than Ogre, however Axiom has unarguably superceded Ogre now so it is not exclusively the languages, but still remains an interesting comparison that isn't just a "micro-benchmark".

The Quake 2 .NET project is a port of Quake 2 to the .NET framework. Quake 2 .NET is compiled as a managed C++ application. However, managed c++/C# both compile to MSIL which is why I typically consider it in native vs managed benchmarks ( which this essentially is ). The managed version of Quake actually ran faster than the native version on the first build which was optimized only for "Pentiums". After changing compile options and compiling for Pentium4+ machines, the native code won out by about 15%.

Most benchmarks which are biased towards C++ tend to put C# at 5-15% slower. Most benchmarks biased towards C# tend to put it at 10% faster to 5% slower. Hence, the 3% is pulled out of this mess as an average with a bias towards real world applications as opposed to biased benchmarks. Feel free to argue the point or the references, but there's no need for grammatically incorrect slanders just because you disagree.

[edited by - haro on April 17, 2004 5:47:22 AM]

Share this post


Link to post
Share on other sites

This topic is 4979 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.

  • Advertisement